Fix crash when window gets removed during windows update loop

This commit is contained in:
Wojtek Figat
2023-10-22 15:56:25 +02:00
parent 1280e61af0
commit c88e184df3
2 changed files with 9 additions and 4 deletions

View File

@@ -513,7 +513,9 @@ DEFINE_INTERNAL_CALL(void) EditorInternal_RunVisualScriptBreakpointLoopTick(floa
WindowsManager::WindowsLocker.Unlock(); WindowsManager::WindowsLocker.Unlock();
} }
WindowsManager::WindowsLocker.Lock(); WindowsManager::WindowsLocker.Lock();
for (auto& win : WindowsManager::Windows) Array<Window*, InlinedAllocation<32>> windows;
windows.Add(WindowsManager::Windows);
for (Window* win : windows)
{ {
if (win->IsVisible()) if (win->IsVisible())
win->OnUpdate(deltaTime); win->OnUpdate(deltaTime);

View File

@@ -59,9 +59,11 @@ void WindowsManagerService::Update()
// Update windows // Update windows
const float deltaTime = Time::Update.UnscaledDeltaTime.GetTotalSeconds(); const float deltaTime = Time::Update.UnscaledDeltaTime.GetTotalSeconds();
WindowsManager::WindowsLocker.Lock(); WindowsManager::WindowsLocker.Lock();
for (Window* win : WindowsManager::Windows) Array<Window*, InlinedAllocation<32>> windows;
windows.Add(WindowsManager::Windows);
for (Window* win : windows)
{ {
if (win && win->IsVisible()) if (win->IsVisible())
win->OnUpdate(deltaTime); win->OnUpdate(deltaTime);
} }
WindowsManager::WindowsLocker.Unlock(); WindowsManager::WindowsLocker.Unlock();
@@ -71,7 +73,8 @@ void WindowsManagerService::Dispose()
{ {
// Close remaining windows // Close remaining windows
WindowsManager::WindowsLocker.Lock(); WindowsManager::WindowsLocker.Lock();
auto windows = WindowsManager::Windows; Array<Window*, InlinedAllocation<32>> windows;
windows.Add(WindowsManager::Windows);
for (Window* win : windows) for (Window* win : windows)
{ {
win->Close(ClosingReason::EngineExit); win->Close(ClosingReason::EngineExit);