From f53fc1f751a74bec3596694fe3ada16d91e0e53c Mon Sep 17 00:00:00 2001 From: phobos2077 Date: Sat, 6 Jul 2024 20:56:00 +0200 Subject: [PATCH] Fix dangling pointer when using USE_HIRES_IMAGES and returning to main menu --- sfall/HRP/MainMenu.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/sfall/HRP/MainMenu.cpp b/sfall/HRP/MainMenu.cpp index 60ece09e8..25e8d0512 100644 --- a/sfall/HRP/MainMenu.cpp +++ b/sfall/HRP/MainMenu.cpp @@ -103,8 +103,8 @@ static long __fastcall main_menu_create_hook_add_win(long h, long y, long color, if (MainMenuScreen::USE_HIRES_IMAGES) { if (mainBackgroundFrm == nullptr) { - mainBackgroundFrm = sf::LoadUnlistedFrmCached("HR_MAINMENU.frm", fo::ArtType::OBJ_TYPE_INTRFACE); - btnBackgroundFrm = sf::LoadUnlistedFrmCached("HR_MENU_BG.frm", fo::ArtType::OBJ_TYPE_INTRFACE); + mainBackgroundFrm = sf::LoadUnlistedFrm("HR_MAINMENU.frm", fo::ArtType::OBJ_TYPE_INTRFACE); + btnBackgroundFrm = sf::LoadUnlistedFrm("HR_MENU_BG.frm", fo::ArtType::OBJ_TYPE_INTRFACE); } if (mainBackgroundFrm != nullptr) { sw = mainBackgroundFrm->frameData[0].width; @@ -276,8 +276,14 @@ static __declspec(naked) void main_menu_create_hook_register_button() { static void FreeMainMenuImages() { // Reset FRM pointers so they can be loaded again after Art cache is reset. - mainBackgroundFrm = nullptr; - btnBackgroundFrm = nullptr; + if (mainBackgroundFrm != nullptr) { + sf::UnloadFrmFile(mainBackgroundFrm); + mainBackgroundFrm = nullptr; + } + if (btnBackgroundFrm != nullptr) { + sf::UnloadFrmFile(btnBackgroundFrm); + btnBackgroundFrm = nullptr; + } if (buttonImageData) { delete[] buttonImageData; buttonImageData = nullptr;