Skip to content

Commit e6901a2

Browse files
committed
Fix InvalidOperationException when ExitGUIException is thrown inside PropertyScope
1 parent c54c2d3 commit e6901a2

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

Assets/Editor Toolbox/Editor/Drawers/Toolbox/PropertySelf/ReferencePickerAttributeDrawer.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ private Rect PrepareTypePropertyPosition(in Rect labelPosition, in Rect inputPos
102102

103103
protected override void OnGuiSafe(SerializedProperty property, GUIContent label, ReferencePickerAttribute attribute)
104104
{
105-
using (var propertyScope = new PropertyScope(property, label))
105+
//NOTE: we want to close scope manually because ExitGUIException can interrupt drawing and SerializedProperties stack
106+
using (var propertyScope = new PropertyScope(property, label, closeManually: true))
106107
{
107108
UpdateContexts(attribute);
108109

@@ -120,6 +121,7 @@ protected override void OnGuiSafe(SerializedProperty property, GUIContent label,
120121
}
121122

122123
EditorGUI.indentLevel--;
124+
propertyScope.Close();
123125
}
124126
}
125127

Assets/Editor Toolbox/Editor/Internal/PropertyScope.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,18 @@ namespace Toolbox.Editor.Internal
1212
internal class PropertyScope : IDisposable
1313
{
1414
private readonly SerializedProperty property;
15+
private readonly bool closeManually;
16+
private bool isClosed;
1517

18+
public PropertyScope(SerializedProperty property, GUIContent label) : this(property, label, false)
19+
{ }
1620

17-
public PropertyScope(SerializedProperty property, GUIContent label)
21+
public PropertyScope(SerializedProperty property, GUIContent label, bool closeManually)
1822
{
1923
this.property = property;
24+
this.closeManually = closeManually;
25+
isClosed = false;
26+
2027
ToolboxEditorGui.BeginProperty(property, ref label, out var rect);
2128
HandleEvents(rect);
2229
TryDrawLabel(rect, label);
@@ -50,9 +57,20 @@ private void TryDrawLabel(Rect rect, GUIContent label)
5057
}
5158

5259

53-
public void Dispose()
60+
public void Close()
5461
{
5562
ToolboxEditorGui.CloseProperty();
63+
isClosed = true;
64+
}
65+
66+
public void Dispose()
67+
{
68+
if (closeManually || isClosed)
69+
{
70+
return;
71+
}
72+
73+
Close();
5674
}
5775

5876

0 commit comments

Comments
 (0)