Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit 5a49be6

Browse files
committed
fix crash when editor closes
1 parent a033f08 commit 5a49be6

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

Runtime/editor/editor_window.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,33 @@ namespace Unity.UIWidgets.editor {
1515
#if UNITY_EDITOR
1616
public abstract class UIWidgetsEditorWindow : EditorWindow, WindowHost {
1717
WindowAdapter _windowAdapter;
18-
18+
19+
static readonly List<UIWidgetsEditorWindow> _activeEditorWindows = new List<UIWidgetsEditorWindow>();
20+
21+
[InitializeOnLoadMethod]
22+
static void _OnBaseEditorWindowLoaded()
23+
{
24+
EditorApplication.quitting += () =>
25+
{
26+
foreach (var editorWindow in _activeEditorWindows) {
27+
editorWindow.OnDisable();
28+
}
29+
30+
_activeEditorWindows.Clear();
31+
};
32+
}
33+
1934
public UIWidgetsEditorWindow() {
2035
this.wantsMouseMove = true;
2136
this.wantsMouseEnterLeaveWindow = true;
37+
38+
_activeEditorWindows.Add(this);
39+
}
40+
41+
void OnDestroy() {
42+
if (_activeEditorWindows.Contains(this)) {
43+
_activeEditorWindows.Remove(this);
44+
}
2245
}
2346

2447
protected virtual void OnEnable() {

0 commit comments

Comments
 (0)