Skip to content

Commit 68b4494

Browse files
committed
Use EditorApplication.update instead of OnInspectorUpdate, because OnInspectorUpdate isn't called without any input interaction. So with the earlier changes, you could capture a snapshot and when you don't move the mouse, the window wouldn't update and thus show no progress.
1 parent 9eb7833 commit 68b4494

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

Editor/Scripts/HeapExplorerWindow.cs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Heap Explorer for Unity. Copyright (c) 2019-2020 Peter Schraut (www.console-dev.de). See LICENSE.md
33
// https://github.com/pschraut/UnityHeapExplorer/
44
//
5+
#pragma warning disable 0414
56
using System.Collections;
67
using System.Collections.Generic;
78
using UnityEngine;
@@ -37,7 +38,6 @@ public PackedMemorySnapshot snapshot
3738
}
3839
}
3940

40-
#pragma warning disable 0414
4141
[NonSerialized] TestVariables m_TestVariables = new TestVariables(); // Allows me to easily check/test various types when capturing a snapshot in the editor.
4242
[NonSerialized] bool m_IsCapturing; // Whether the tool is currently capturing a memory snapshot
4343
[NonSerialized] GotoHistory m_GotoHistory = new GotoHistory();
@@ -48,7 +48,6 @@ public PackedMemorySnapshot snapshot
4848
[NonSerialized] Rect m_FileToolbarButtonRect; // The rect of the File button in the toolbar menu. Used as position to open its popup menu.
4949
[NonSerialized] Rect m_ViewToolbarButtonRect; // The rect of the View button in the toolbar menu. Used as position to open its popup menu.
5050
[NonSerialized] Rect m_CaptureToolbarButtonRect; // The rect of the Capture button in the toolbar menu. Used as position to open its popup menu.
51-
public bool isClosing { get; private set; }
5251
[NonSerialized] List<AbstractThreadJob> m_ThreadJobs = new List<AbstractThreadJob>(); // Jobs to run on a background thread
5352
[NonSerialized] List<AbstractThreadJob> m_IntegrationJobs = new List<AbstractThreadJob>(); // These are completed thread jobs that are not being integrated on the main-thread
5453
[NonSerialized] bool m_Repaint; // Threads write to this variable rather than calling window.Repaint()
@@ -59,9 +58,11 @@ public PackedMemorySnapshot snapshot
5958
[NonSerialized] int m_BusyDraws;
6059
[NonSerialized] List<Exception> m_Exceptions = new List<Exception>(); // If exception occur in threaded jobs, these are collected and logged on the main thread
6160
[NonSerialized] bool m_CloseDueToError; // If set to true, will close the editor during the next Update
61+
[NonSerialized] double m_LastRepaintTimestamp; // The EditorApplication.timeSinceStartup when a Repaint() was issued
6262

6363
static List<System.Type> s_ViewTypes = new List<Type>();
64-
#pragma warning restore 0414
64+
65+
public bool isClosing { get; private set; }
6566

6667
bool useThreads
6768
{
@@ -153,12 +154,16 @@ void OnEnable()
153154
minSize = new Vector2(800, 600);
154155
snapshotPath = "";
155156
showInternalMemorySections = showInternalMemorySections;
157+
m_LastRepaintTimestamp = 0;
158+
m_Repaint = true;
156159

157160
m_ThreadJobs = new List<AbstractThreadJob>();
158161
m_Thread = new System.Threading.Thread(ThreadLoop);
159162
m_Thread.Start();
160163

161164
CreateViews();
165+
166+
EditorApplication.update += OnEditorApplicationUpdate;
162167
}
163168

164169
void OnDisable()
@@ -174,11 +179,23 @@ void OnDisable()
174179
m_Thread.Join(); // wait for thread exit
175180
m_Thread = null;
176181

182+
EditorApplication.update -= OnEditorApplicationUpdate;
183+
177184
DestroyViews();
178185
}
179186

180-
void OnInspectorUpdate()
187+
void OnEditorApplicationUpdate()
181188
{
189+
if (m_Repaint || (m_Heap != null && m_Heap.isBusy))
190+
{
191+
if (m_LastRepaintTimestamp+0.05f < EditorApplication.timeSinceStartup)
192+
{
193+
m_Repaint = false;
194+
m_LastRepaintTimestamp = EditorApplication.timeSinceStartup;
195+
Repaint();
196+
}
197+
}
198+
182199
if (m_CloseDueToError)
183200
{
184201
EditorUtility.DisplayDialog("Heap Explorer - ERROR", "An error occured. Please check Unity's Debug Console for more information.", "OK");
@@ -346,12 +363,6 @@ void OnGUI()
346363
m_Repaint = true;
347364
DrawBusy(abortButton);
348365
}
349-
350-
if (Event.current.type == EventType.Repaint && m_Repaint)
351-
{
352-
m_Repaint = false;
353-
Repaint();
354-
}
355366
}
356367

357368
public void SetBusy(string text)

0 commit comments

Comments
 (0)