From 461249d82c6b970a250f2bdb2c05a0158f2a5eb4 Mon Sep 17 00:00:00 2001 From: Matt <5415177+ZehMatt@users.noreply.github.com> Date: Tue, 13 Aug 2024 00:49:58 +0300 Subject: [PATCH] Fix #22316: Always recreate the window when changing drawing engine --- distribution/changelog.txt | 1 + .../engines/HardwareDisplayDrawingEngine.cpp | 8 ++++++++ src/openrct2-ui/windows/Options.cpp | 5 +---- src/openrct2/drawing/Drawing.cpp | 14 ++------------ src/openrct2/drawing/Drawing.h | 2 +- 5 files changed, 13 insertions(+), 17 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index fe7a643745cb..6cb267ad7f54 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -12,6 +12,7 @@ - Change: [#22491] Scrollbars are now hidden if the scrollable widget is not actually overflowing. - Fix: [#21908] Errors showing up when placing/moving track design previews. - Fix: [#22307] Hover tooltips in financial charts are not invalidated properly. +- Fix: [#22316] Potential crash when switching the drawing engine while the game is running. - Fix: [#22395, #22396] Misaligned tick marks in financial and guest count graphs (original bug). 0.4.13 (2024-08-04) diff --git a/src/openrct2-ui/drawing/engines/HardwareDisplayDrawingEngine.cpp b/src/openrct2-ui/drawing/engines/HardwareDisplayDrawingEngine.cpp index 13f7cbf185dd..f16d14c5bc41 100644 --- a/src/openrct2-ui/drawing/engines/HardwareDisplayDrawingEngine.cpp +++ b/src/openrct2-ui/drawing/engines/HardwareDisplayDrawingEngine.cpp @@ -62,6 +62,14 @@ class HardwareDisplayDrawingEngine final : public X8DrawingEngine ~HardwareDisplayDrawingEngine() override { + if (_screenTexture != nullptr) + { + SDL_DestroyTexture(_screenTexture); + } + if (_scaledScreenTexture != nullptr) + { + SDL_DestroyTexture(_scaledScreenTexture); + } SDL_FreeFormat(_screenTextureFormat); SDL_DestroyRenderer(_sdlRenderer); } diff --git a/src/openrct2-ui/windows/Options.cpp b/src/openrct2-ui/windows/Options.cpp index 80cee2c0b476..2a3e32bf3b2c 100644 --- a/src/openrct2-ui/windows/Options.cpp +++ b/src/openrct2-ui/windows/Options.cpp @@ -714,7 +714,6 @@ static Widget *window_options_page_widgets[] = { break; case WIDX_MINIMIZE_FOCUS_LOSS: Config::Get().general.MinimizeFullscreenFocusLoss ^= 1; - RefreshVideo(false); Config::Save(); Invalidate(); break; @@ -853,12 +852,10 @@ static Widget *window_options_page_widgets[] = { case WIDX_DRAWING_ENGINE_DROPDOWN: if (dropdownIndex != EnumValue(Config::Get().general.DrawingEngine)) { - DrawingEngine srcEngine = drawing_engine_get_type(); DrawingEngine dstEngine = static_cast(dropdownIndex); Config::Get().general.DrawingEngine = dstEngine; - bool recreate_window = DrawingEngineRequiresNewWindow(srcEngine, dstEngine); - RefreshVideo(recreate_window); + RefreshVideo(); Config::Save(); Invalidate(); } diff --git a/src/openrct2/drawing/Drawing.cpp b/src/openrct2/drawing/Drawing.cpp index e1e0f20e4370..1e35a1129ff9 100644 --- a/src/openrct2/drawing/Drawing.cpp +++ b/src/openrct2/drawing/Drawing.cpp @@ -1124,19 +1124,9 @@ void UpdatePaletteEffects() } } -void RefreshVideo(bool recreateWindow) +void RefreshVideo() { - if (recreateWindow) - { - ContextRecreateWindow(); - } - else - { - DrawingEngineDispose(); - DrawingEngineInit(); - DrawingEngineResize(); - } - + ContextRecreateWindow(); DrawingEngineSetPalette(gPalette); GfxInvalidateScreen(); } diff --git a/src/openrct2/drawing/Drawing.h b/src/openrct2/drawing/Drawing.h index 958d5d77ec1a..76ed0107419b 100644 --- a/src/openrct2/drawing/Drawing.h +++ b/src/openrct2/drawing/Drawing.h @@ -630,7 +630,7 @@ std::optional GetPaletteMapForColour(colour_t paletteId); void UpdatePalette(const uint8_t* colours, int32_t start_index, int32_t num_colours); void UpdatePaletteEffects(); -void RefreshVideo(bool recreateWindow); +void RefreshVideo(); void ToggleWindowedMode(); #include "NewDrawing.h"