From 5b4b6f2c520080321360adfd6c1752f1bf3bfd59 Mon Sep 17 00:00:00 2001 From: Patedam Date: Wed, 8 Jan 2025 20:22:42 -0500 Subject: [PATCH] Fix DestroyPlatformWindow crashing when called in Shutdown of the application --- Juliet/src/Core/HAL/Display/Display.cpp | 8 +++++++- JulietApp/Editor/EditorMain_win32.cpp | 20 ++++---------------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/Juliet/src/Core/HAL/Display/Display.cpp b/Juliet/src/Core/HAL/Display/Display.cpp index c0b7142..3123c77 100644 --- a/Juliet/src/Core/HAL/Display/Display.cpp +++ b/Juliet/src/Core/HAL/Display/Display.cpp @@ -53,7 +53,10 @@ namespace Juliet } // Destroy all Windows that are still alive - DestroyPlatformWindow(CurrentDisplayDevice->MainWindow); + if (CurrentDisplayDevice->MainWindow) + { + DestroyPlatformWindow(CurrentDisplayDevice->MainWindow); + } CurrentDisplayDevice->Shutdown(CurrentDisplayDevice); // Free anything that was freed by the shutdown and then free the display @@ -89,11 +92,14 @@ namespace Juliet void DestroyPlatformWindow(NonNullPtr window) { + Assert(CurrentDisplayDevice->MainWindow == window.Get()); + HideWindow(window); CurrentDisplayDevice->DestroyPlatformWindow(CurrentDisplayDevice, window); Free(window.Get()); + CurrentDisplayDevice->MainWindow = nullptr; } void ShowWindow(NonNullPtr window) diff --git a/JulietApp/Editor/EditorMain_win32.cpp b/JulietApp/Editor/EditorMain_win32.cpp index b0036e0..53ac097 100644 --- a/JulietApp/Editor/EditorMain_win32.cpp +++ b/JulietApp/Editor/EditorMain_win32.cpp @@ -31,12 +31,14 @@ namespace Juliet { Log(LogLevel::Message, LogCategory::Editor, "Shutdown Editor Application..."); - // DestroyOSWindow(MainWindow); + if (MainWindow ) + { + DestroyPlatformWindow(MainWindow); + } } void Win32EditorApplication::Update() { - // UpdateOSWindowState(MainWindow); SystemEvent evt; while (GetEvent(evt)) { @@ -47,20 +49,6 @@ namespace Juliet Running = false; } } - - if (evt.Type == EventType::Key_Down) - { - if (evt.Data.Keyboard.Key.ScanCode == ScanCode::Escape) - { - Running = false; - } - } - - // Other way to do it - if (IsKeyDown(ScanCode::Q)) - { - Running = false; - } } }