From 2cd1479c437bd659c4726d8b91f936ddf1c95e72 Mon Sep 17 00:00:00 2001 From: MaikelChan Date: Thu, 24 Mar 2022 07:37:45 +0100 Subject: [PATCH] Fixed window not properly disposing raylib and OpenGL when closing. Closing the window with the X button will not close it immediately during the rendering of a frame, causing it to actually crash, but will set the engine in a pending state until it finishes the current frame. --- OTRGui/src/game/game.cpp | 4 ++-- OTRGui/src/game/game.h | 5 +++++ OTRGui/src/main.cpp | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/OTRGui/src/game/game.cpp b/OTRGui/src/game/game.cpp index 3fc6438a8..87465186f 100644 --- a/OTRGui/src/game/game.cpp +++ b/OTRGui/src/game/game.cpp @@ -116,7 +116,7 @@ void OTRGame::draw() { DrawTexture(titleTex, windowSize.x / 2 - titleTex.width / 2, titlebar.height / 2 - titleTex.height / 2, WHITE); if (UIUtils::GuiIcon("Exit", windowSize.x - 36, titlebar.height / 2 - 10) && (extracting && currentStep.find("Done") != std::string::npos || !extracting)) { - CloseWindow(); + closeRequested = true; } BeginMode3D(camera); @@ -157,7 +157,7 @@ void OTRGame::draw() { UIUtils::GuiShadowText(currentStep.c_str(), 0, windowSize.y / 2, 10, WHITE, BLACK, windowSize.x, true); } - EndDrawing(); + EndDrawing(); } void setCurrentStep(const std::string& step) { diff --git a/OTRGui/src/game/game.h b/OTRGui/src/game/game.h index b284f857a..bd74b1c3f 100644 --- a/OTRGui/src/game/game.h +++ b/OTRGui/src/game/game.h @@ -19,6 +19,8 @@ public: void update(); void draw(); void exit(); + + inline bool CloseRequested() { return closeRequested; } protected: void LoadTexture(const std::string& name, const std::string& path) { const Image tmp = LoadImage(path.c_str()); @@ -32,6 +34,9 @@ protected: SetTextureFilter(font.texture, TEXTURE_FILTER_POINT); Fonts[name] = font; } + +private: + bool closeRequested = false; }; extern OTRGame* Game; diff --git a/OTRGui/src/main.cpp b/OTRGui/src/main.cpp index 87c9d26ee..d2cee9fc5 100644 --- a/OTRGui/src/main.cpp +++ b/OTRGui/src/main.cpp @@ -17,7 +17,7 @@ void UpdateDrawFrame(void) { } int main() { - constexpr Vector2 windowSize = Vector2(400, 200); + constexpr Vector2 windowSize = Vector2(400, 200); SetTargetFPS(144); SetConfigFlags(FLAG_WINDOW_HIGHDPI); SetConfigFlags(FLAG_WINDOW_UNDECORATED); @@ -32,7 +32,7 @@ int main() { Game = new OTRGame(); Game->preload(); Game->init(); - while(!WindowShouldClose()) { + while(!WindowShouldClose() && !Game->CloseRequested()) { UpdateDrawFrame(); } CloseWindow();