diff --git a/Scripts/Editor/NodeEditor.cs b/Scripts/Editor/NodeEditor.cs index ddfd626..a562fdf 100644 --- a/Scripts/Editor/NodeEditor.cs +++ b/Scripts/Editor/NodeEditor.cs @@ -39,10 +39,28 @@ namespace XNodeEditor { string[] excludes = { "m_Script", "graph", "position", "ports" }; #if ODIN_INSPECTOR - InspectorUtilities.BeginDrawPropertyTree(objectTree, true); - GUIHelper.PushLabelWidth(84); - objectTree.Draw(true); + try + { +#if ODIN_INSPECTOR_3 + objectTree.BeginDraw( true ); +#else + InspectorUtilities.BeginDrawPropertyTree(objectTree, true); +#endif + } + catch ( ArgumentNullException ) + { + objectTree.EndDraw(); + NodeEditor.DestroyEditor(this.target); + return; + } + + GUIHelper.PushLabelWidth( 84 ); + objectTree.Draw( true ); +#if ODIN_INSPECTOR_3 + objectTree.EndDraw(); +#else InspectorUtilities.EndDrawPropertyTree(objectTree); +#endif GUIHelper.PopLabelWidth(); #else diff --git a/Scripts/Editor/NodeEditorBase.cs b/Scripts/Editor/NodeEditorBase.cs index 1fc28c7..e556a10 100644 --- a/Scripts/Editor/NodeEditorBase.cs +++ b/Scripts/Editor/NodeEditorBase.cs @@ -24,7 +24,7 @@ namespace XNodeEditor.Internal { private PropertyTree _objectTree; public PropertyTree objectTree { get { - if (this._objectTree == null) { + if (this._objectTree == null){ try { bool wasInEditor = NodeEditor.inNodeEditor; NodeEditor.inNodeEditor = true; @@ -58,6 +58,16 @@ namespace XNodeEditor.Internal { return editor; } + public static void DestroyEditor( K target ) + { + if ( target == null ) return; + T editor; + if ( editors.TryGetValue( target, out editor ) ) + { + editors.Remove( target ); + } + } + private static Type GetEditorType(Type type) { if (type == null) return null; if (editorTypes == null) CacheCustomEditors();