Fixed bug where rendering inspectors for scripts that contain uninitialized List<T>s causes crashes #257

Merged
Pycorax merged 1 commits from SP3-6-c-scripting into main 2022-11-23 13:49:42 +08:00
2 changed files with 7 additions and 0 deletions
Showing only changes of commit 67db744856 - Show all commits

View File

@ -23,6 +23,7 @@ public class RaccoonShowcase : Script
[Range(-5, 5)]
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<int> nullList;
public FontAsset fontAsset;
public MeshAsset mesh;
public MaterialAsset matAsset;

View File

@ -189,6 +189,12 @@ namespace SHADE
System::Type^ listType = field->FieldType->GenericTypeArguments[0];
RangeAttribute^ rangeAttrib = hasAttribute<RangeAttribute^>(field);
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))
{