From b1dfbe99259503f377e4308650187d5df7780348 Mon Sep 17 00:00:00 2001 From: AllMeatball <181806857+AllMeatball@users.noreply.github.com> Date: Fri, 16 May 2025 21:08:45 +0000 Subject: [PATCH] isleapp: Show error dialog if NOCD.si or ISLE.si fails to load (#95) * isleapp: Show error dialog if NOCD.si fails to load * isleapp: Return bool in IsleApp::Tick foxtacles recommended me to return a boolean for if tick failed instead of just setting `g_closed` and setting `g_closeResult` to set the return value of the program exit. I also think this is the better solution. since a similar solution was used in LoadConfig. * isleapp: Better error logs & return false in places foxtacles recommended to use SDL's logging api to show detailed errors and using false in two places where it should exit because of failure. This commit adds these two things. * isleapp: Add missing error dialog when ISLE.si fails * isleapp: Add missing error dialog when ISLE.si fails * isleapp: Remove weird duplicate message box * Move error dialog to loop --------- Co-authored-by: Christian Semmler --- ISLE/isleapp.cpp | 51 ++++++++++++++++++++++++++++++++++++------------ ISLE/isleapp.h | 2 +- 2 files changed, 39 insertions(+), 14 deletions(-) diff --git a/ISLE/isleapp.cpp b/ISLE/isleapp.cpp index ae034a2e..a16b6251 100644 --- a/ISLE/isleapp.cpp +++ b/ISLE/isleapp.cpp @@ -30,6 +30,8 @@ #include "roi/legoroi.h" #include "viewmanager/viewmanager.h" +#include + #define SDL_MAIN_USE_CALLBACKS #include #include @@ -289,7 +291,16 @@ SDL_AppResult SDL_AppIterate(void* appstate) return SDL_APP_SUCCESS; } - g_isle->Tick(); + if (!g_isle->Tick()) { + SDL_ShowSimpleMessageBox( + SDL_MESSAGEBOX_ERROR, + "LEGO® Island Error", + "\"LEGO® Island\" failed to start.\nPlease quit all other applications and try again." + "\nFailed to initialize; see logs for details", + NULL + ); + return SDL_APP_FAILURE; + } if (!g_closed) { if (g_reqEnableRMDevice) { @@ -304,7 +315,16 @@ SDL_AppResult SDL_AppIterate(void* appstate) } if (g_mousedown && g_mousemoved && g_isle) { - g_isle->Tick(); + if (!g_isle->Tick()) { + SDL_ShowSimpleMessageBox( + SDL_MESSAGEBOX_ERROR, + "LEGO® Island Error", + "\"LEGO® Island\" failed to start.\nPlease quit all other applications and try again." + "\nFailed to initialize; see logs for details", + NULL + ); + return SDL_APP_FAILURE; + } } if (g_mousemoved) { @@ -683,7 +703,7 @@ bool IsleApp::LoadConfig() } // FUNCTION: ISLE 0x402c20 -inline void IsleApp::Tick() +inline bool IsleApp::Tick() { // GLOBAL: ISLE 0x4101c0 static MxLong g_lastFrameTime = 0; @@ -693,17 +713,17 @@ inline void IsleApp::Tick() if (!m_windowActive) { SDL_Delay(1); - return; + return true; } if (!Lego()) { - return; + return true; } if (!TickleManager()) { - return; + return true; } if (!Timer()) { - return; + return true; } MxLong currentTime = Timer()->GetRealTime(); @@ -713,7 +733,7 @@ inline void IsleApp::Tick() if (m_frameDelta + g_lastFrameTime >= currentTime) { SDL_Delay(1); - return; + return true; } if (!Lego()->IsPaused()) { @@ -722,12 +742,12 @@ inline void IsleApp::Tick() g_lastFrameTime = currentTime; if (g_startupDelay == 0) { - return; + return true; } g_startupDelay--; if (g_startupDelay != 0) { - return; + return true; } LegoOmni::GetInstance()->CreateBackgroundAudio(); @@ -739,7 +759,8 @@ inline void IsleApp::Tick() if (!stream) { stream = Streamer()->Open("\\lego\\scripts\\nocd", MxStreamer::e_diskStream); if (!stream) { - return; + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to open NOCD.si: Streamer failed to load"); + return false; } ds.SetAtomId(stream->GetAtom()); @@ -748,7 +769,8 @@ inline void IsleApp::Tick() VideoManager()->EnableFullScreenMovie(TRUE, TRUE); if (Start(&ds) != SUCCESS) { - return; + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to open NOCD.si: Failed to start initial action"); + return false; } } else { @@ -756,10 +778,13 @@ inline void IsleApp::Tick() ds.SetUnknown24(-1); ds.SetObjectId(0); if (Start(&ds) != SUCCESS) { - return; + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to open ISLE.si: Failed to start initial action"); + return false; } m_gameStarted = TRUE; } + + return true; } // FUNCTION: ISLE 0x402e80 diff --git a/ISLE/isleapp.h b/ISLE/isleapp.h index 979ef16c..7fd3c84f 100644 --- a/ISLE/isleapp.h +++ b/ISLE/isleapp.h @@ -37,7 +37,7 @@ class IsleApp { MxResult SetupWindow(); bool LoadConfig(); - void Tick(); + bool Tick(); void SetupCursor(Cursor p_cursor); static MxU8 MapMouseButtonFlagsToModifier(SDL_MouseButtonFlags p_flags);