From 67db7448564f71c6acedcd31dc20cdabc3029159 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Wed, 23 Nov 2022 10:08:48 +0800 Subject: [PATCH] Uninitialized List<> will no longer cause crashes with the script inspector --- Assets/Scripts/RaccoonShowcase.cs | 1 + SHADE_Managed/src/Editor/Editor.cxx | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/Assets/Scripts/RaccoonShowcase.cs b/Assets/Scripts/RaccoonShowcase.cs index 1da191fd..424a8a3e 100644 --- a/Assets/Scripts/RaccoonShowcase.cs +++ b/Assets/Scripts/RaccoonShowcase.cs @@ -23,6 +23,7 @@ public class RaccoonShowcase : Script [Range(-5, 5)] public List intList = new List(new int[] { 2, 8, 2, 6, 8, 0, 1 }); public List enumList = new List(new Light.Type[] { Light.Type.Point, Light.Type.Directional, Light.Type.Ambient }); + public List nullList; public FontAsset fontAsset; public MeshAsset mesh; public MaterialAsset matAsset; diff --git a/SHADE_Managed/src/Editor/Editor.cxx b/SHADE_Managed/src/Editor/Editor.cxx index 29e3da36..80c73d4f 100644 --- a/SHADE_Managed/src/Editor/Editor.cxx +++ b/SHADE_Managed/src/Editor/Editor.cxx @@ -189,6 +189,12 @@ namespace SHADE System::Type^ listType = field->FieldType->GenericTypeArguments[0]; RangeAttribute^ rangeAttrib = hasAttribute(field); System::Collections::IList^ iList = safe_cast(field->GetValue(object)); + if (iList == nullptr) + { + // Create if the list does not exist + iList = safe_cast(System::Activator::CreateInstance(field->FieldType)); + field->SetValue(object, iList); + } if (SHEditorUI::CollapsingHeader(Convert::ToNative(field->Name), &isHovered)) { -- 2.40.1