From eaf292c420c8c6b11da4a500e9e39cefabed6524 Mon Sep 17 00:00:00 2001 From: niuus <30782922+niuus@users.noreply.github.com> Date: Wed, 24 Jul 2019 20:40:34 -0400 Subject: [PATCH] Cleanup screenshot memory management [Tantric] This should fix the preview image not displaying on Gamecube. --- source/menu.cpp | 9 ++------- source/video.cpp | 10 ++++++++++ source/video.h | 1 + 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/source/menu.cpp b/source/menu.cpp index d576add..f16ef7a 100644 --- a/source/menu.cpp +++ b/source/menu.cpp @@ -1575,8 +1575,7 @@ static int MenuGame() delete gameScreenImg; delete gameScreen; gameScreen = NULL; - free(gameScreenPng); - gameScreenPng = NULL; + ClearScreenshot(); gameScreenImg = new GuiImage(screenwidth, screenheight, (GXColor){175, 200, 215, 255}); gameScreenImg->ColorStripe(10); mainWindow->Insert(gameScreenImg, 0); @@ -4366,11 +4365,7 @@ MainMenu (int menu) if(gameScreen) delete gameScreen; - if(gameScreenPng) - { - free(gameScreenPng); - gameScreenPng = NULL; - } + ClearScreenshot(); // wait for keys to be depressed while(MenuRequested()) diff --git a/source/video.cpp b/source/video.cpp index ad90a4a..4edeb62 100644 --- a/source/video.cpp +++ b/source/video.cpp @@ -908,6 +908,16 @@ void TakeScreenshot() } } +void ClearScreenshot() +{ + if(gameScreenPng) + { + gameScreenPngSize = 0; + free(gameScreenPng); + gameScreenPng = NULL; + } +} + /**************************************************************************** * ResetVideo_Menu * diff --git a/source/video.h b/source/video.h index 83a46a1..c7b2747 100644 --- a/source/video.h +++ b/source/video.h @@ -25,6 +25,7 @@ void setGFX(); void update_video (int width, int height); void ResetVideo_Menu(); void TakeScreenshot(); +void ClearScreenshot(); void Menu_Render(); void Menu_DrawImg(f32 xpos, f32 ypos, u16 width, u16 height, u8 data[], f32 degrees, f32 scaleX, f32 scaleY, u8 alphaF ); void Menu_DrawRectangle(f32 x, f32 y, f32 width, f32 height, GXColor color, u8 filled);