From f81ecf017898bca31967500050207a0cf5c67a7e Mon Sep 17 00:00:00 2001 From: Maschell Date: Fri, 7 Jun 2024 20:46:42 +0200 Subject: [PATCH] Avoid screen corruption after displaying the environment selection screen --- source/main.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/source/main.cpp b/source/main.cpp index d721497..0f38336 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -7,10 +7,12 @@ #include #include #include +#include #include #include #include #include +#include #include #include #include @@ -421,7 +423,25 @@ void LoadAndRunModule(std::string_view filepath, std::string_view environment_pa SetupKernelModule(); } +void ClearSavedFrameBuffers() { + // If GX2 is running make sure to shut it down and free all existing memory in the saved-frame area. + if (GX2GetMainCoreId() != -1) { + GX2SetTVEnable(FALSE); + GX2SetDRCEnable(FALSE); + GX2Shutdown(); + } + + __OSClearSavedFrame(OS_SAVED_FRAME_A, OS_SAVED_FRAME_SCREEN_TV); + __OSClearSavedFrame(OS_SAVED_FRAME_A, OS_SAVED_FRAME_SCREEN_DRC); + __OSClearSavedFrame(OS_SAVED_FRAME_B, OS_SAVED_FRAME_SCREEN_TV); + __OSClearSavedFrame(OS_SAVED_FRAME_B, OS_SAVED_FRAME_SCREEN_DRC); +} + std::string EnvironmentSelectionScreen(const std::map &payloads, int32_t autobootIndex) { + + // Clear saved frame buffer to reduce screen corruption + ClearSavedFrameBuffers(); + OSScreenInit(); uint32_t tvBufferSize = OSScreenGetBufferSizeEx(SCREEN_TV); @@ -535,6 +555,9 @@ std::string EnvironmentSelectionScreen(const std::map // Call GX2Init to shut down OSScreen GX2Init(nullptr); + GX2SetTVEnable(FALSE); + GX2SetDRCEnable(FALSE); + free(screenBuffer); if (autoBoot != autobootIndex) {