From 7040e3992b257105674987cd4d411d0e87f69a09 Mon Sep 17 00:00:00 2001 From: bd_ Date: Sat, 28 Sep 2024 19:56:01 -0700 Subject: [PATCH] fix: ROSimulator UI refresh sometimes gets wedged Closes: #1219 --- .../ReactiveObjects/Simulator/ROSimulator.cs | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/Editor/ReactiveObjects/Simulator/ROSimulator.cs b/Editor/ReactiveObjects/Simulator/ROSimulator.cs index c6bee26a..3aaf3237 100644 --- a/Editor/ReactiveObjects/Simulator/ROSimulator.cs +++ b/Editor/ReactiveObjects/Simulator/ROSimulator.cs @@ -65,27 +65,41 @@ namespace nadena.dev.modular_avatar.core.editor.Simulator private void OnEnable() { - PropertyOverrides.Value = ImmutableDictionary.Empty; - MenuItemOverrides.Value = ImmutableDictionary.Empty; - EditorApplication.delayCall += LoadUI; - Selection.selectionChanged += SelectionChanged; - is_enabled = true; + EditorApplication.delayCall += () => + { + PropertyOverrides.Value = ImmutableDictionary.Empty; + MenuItemOverrides.Value = ImmutableDictionary.Empty; + EditorApplication.delayCall += LoadUI; + EditorApplication.update += PeriodicRefresh; + Selection.selectionChanged += SelectionChanged; + is_enabled = true; + }; } private void OnDisable() { - Selection.selectionChanged -= SelectionChanged; is_enabled = false; // Delay this to ensure that we don't try to change this value from within assembly reload callbacks // (which generates a noisy exception) EditorApplication.delayCall += () => { + Selection.selectionChanged -= SelectionChanged; + EditorApplication.update -= PeriodicRefresh; + PropertyOverrides.Value = null; MenuItemOverrides.Value = null; }; } + private void PeriodicRefresh() + { + if (_refreshPending) + { + RefreshUI(); + } + } + private ComputeContext _lastComputeContext; private GameObject currentSelection; private GUIStyle lockButtonStyle; @@ -102,7 +116,9 @@ namespace nadena.dev.modular_avatar.core.editor.Simulator _refreshPending = true; - EditorApplication.delayCall += RefreshUI; + // For some reason, this seems to get dropped occasionally, resulting in us being wedged with _refreshPending = true. + // Instead, we'll trigger this from EditorApplication.update... + // EditorApplication.delayCall += RefreshUI; } private void UpdatePropertyOverride(string prop, bool? enable, float f_val)