Uninitialized List<> will no longer cause crashes with the script inspector

This commit is contained in:
Kah Wei 2022-11-23 10:08:48 +08:00
parent ae85c246ed
commit 67db744856
2 changed files with 7 additions and 0 deletions

View File

@ -23,6 +23,7 @@ public class RaccoonShowcase : Script
[Range(-5, 5)] [Range(-5, 5)]
public List<int> intList = new List<int>(new int[] { 2, 8, 2, 6, 8, 0, 1 }); public List<int> intList = new List<int>(new int[] { 2, 8, 2, 6, 8, 0, 1 });
public List<Light.Type> enumList = new List<Light.Type>(new Light.Type[] { Light.Type.Point, Light.Type.Directional, Light.Type.Ambient }); public List<Light.Type> enumList = new List<Light.Type>(new Light.Type[] { Light.Type.Point, Light.Type.Directional, Light.Type.Ambient });
public List<int> nullList;
public FontAsset fontAsset; public FontAsset fontAsset;
public MeshAsset mesh; public MeshAsset mesh;
public MaterialAsset matAsset; public MaterialAsset matAsset;

View File

@ -189,6 +189,12 @@ namespace SHADE
System::Type^ listType = field->FieldType->GenericTypeArguments[0]; System::Type^ listType = field->FieldType->GenericTypeArguments[0];
RangeAttribute^ rangeAttrib = hasAttribute<RangeAttribute^>(field); RangeAttribute^ rangeAttrib = hasAttribute<RangeAttribute^>(field);
System::Collections::IList^ iList = safe_cast<System::Collections::IList^>(field->GetValue(object)); System::Collections::IList^ iList = safe_cast<System::Collections::IList^>(field->GetValue(object));
if (iList == nullptr)
{
// Create if the list does not exist
iList = safe_cast<System::Collections::IList^>(System::Activator::CreateInstance(field->FieldType));
field->SetValue(object, iList);
}
if (SHEditorUI::CollapsingHeader(Convert::ToNative(field->Name), &isHovered)) if (SHEditorUI::CollapsingHeader(Convert::ToNative(field->Name), &isHovered))
{ {