From c0c0e4d8babe37a2ff72495ad62b6669a8e93a7d Mon Sep 17 00:00:00 2001 From: DepressedTWM Date: Wed, 27 May 2026 23:47:38 +0400 Subject: [PATCH] Fixes and replasing simple messegeboxed with crash() --- binding-mri/binding-mri.cpp | 31 +++++++++++++------------------ src/main.cpp | 21 +++++++++------------ 2 files changed, 22 insertions(+), 30 deletions(-) diff --git a/binding-mri/binding-mri.cpp b/binding-mri/binding-mri.cpp index f2c935b..34b4555 100644 --- a/binding-mri/binding-mri.cpp +++ b/binding-mri/binding-mri.cpp @@ -149,10 +149,6 @@ static void mriBindingInit(){ rb_gv_set("BTEST", rb_bool_new(shState->config().editor.battleTest)); } -static void showMsg(const std::string &msg){ - shState->eThread().showMessageBox(msg.c_str()); -} - static void printP(int argc, VALUE *argv, const char *convMethod, const char *sep){ VALUE dispString = rb_str_buf_new(128); ID conv = rb_intern(convMethod); @@ -165,7 +161,7 @@ static void printP(int argc, VALUE *argv, const char *convMethod, const char *se rb_str_buf_cat2(dispString, sep); } - showMsg(RSTRING_PTR(dispString)); + shState->eThread().showMessageBox(RSTRING_PTR(dispString)); } RB_METHOD(mriPrint){ @@ -332,14 +328,15 @@ static VALUE evalString(VALUE string, VALUE filename, int *state){ static void runCustomScript(const std::string &filename){ std::string scriptData; + char msg[1024]; if (!readFileSDL(filename.c_str(), scriptData)){ - showMsg(std::string("Unable to open '") + filename + "'"); + snprintf(msg, sizeof msg, "Unable to open %s", filename); + crash(msg); return; } - evalString(newStringUTF8(scriptData.c_str(), scriptData.size()), - newStringUTF8(filename.c_str(), filename.size()), NULL); + evalString(newStringUTF8(scriptData.c_str(), scriptData.size()), newStringUTF8(filename.c_str(), filename.size()), NULL); } VALUE kernelLoadDataInt(const char *filename, bool rubyExc); @@ -354,14 +351,11 @@ struct BacktraceData{ static void runRMXPScripts(BacktraceData &btData){ const Config &conf = shState->rtData().config; const std::string &scriptPack = conf.game.scripts; - - if (scriptPack.empty()){ - showMsg("No game scripts specified (missing Game.ini?)"); - return; - } - + char msg[512]; + if (!shState->fileSystem().exists(scriptPack.c_str())){ - showMsg("Unable to open '" + scriptPack + "'"); + snprintf(msg, sizeof msg, "Unable to open '%s'", scriptPack.c_str()); + crash(msg); return; } @@ -373,12 +367,13 @@ static void runRMXPScripts(BacktraceData &btData){ scriptArray = kernelLoadDataInt(scriptPack.c_str(), false); printf("[runRMXPScripts] %s\n", scriptPack.c_str()); }catch (const Exception &e){ - showMsg(std::string("Failed to read script data: ") + e.msg); + snprintf(msg, sizeof msg, "Failed to read script data: %s", e.msg); + crash(msg); return; } if (!RB_TYPE_P(scriptArray, RUBY_T_ARRAY)){ - showMsg("Failed to read script data"); + crash("Failed to read script data"); return; } @@ -429,7 +424,7 @@ static void runRMXPScripts(BacktraceData &btData){ if (result != Z_OK){ static char buffer[256]; snprintf(buffer, sizeof(buffer), "Error decoding script %ld: '%s'\n", i, RSTRING_PTR(scriptName)); - showMsg(buffer); + crash(buffer); break; } diff --git a/src/main.cpp b/src/main.cpp index 3c2ffc8..3437a9c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -98,6 +98,7 @@ int rgssThreadFun(void *userdata){ initGLFunctions(); } catch (const Exception &exc){ + crash(exc.msg.c_str()); rgssThreadError(threadData, exc.msg); SDL_GL_DestroyContext(glCtx); return 0; @@ -129,7 +130,6 @@ int rgssThreadFun(void *userdata){ crash("Error creating OpenAL context"); rgssThreadError(threadData, "Error creating OpenAL context"); SDL_GL_DestroyContext(glCtx); - return 0; } @@ -138,6 +138,7 @@ int rgssThreadFun(void *userdata){ try{ SharedState::initInstance(threadData); }catch (const Exception &exc){ + crash(exc.msg.c_str()); rgssThreadError(threadData, exc.msg); alcDestroyContext(alcCtx); SDL_GL_DestroyContext(glCtx); @@ -160,7 +161,6 @@ int rgssThreadFun(void *userdata){ } static void showInitError(const std::string &msg){ - Debug() << msg; SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error :(", msg.c_str(), 0); } @@ -194,7 +194,7 @@ static void setGamePathInRegistry() { long keyCreateError = RegCreateKeyEx(HKEY_CURRENT_USER, TEXT("Software\\OneShot\\"), 0L, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &key, NULL); if (keyCreateError != ERROR_SUCCESS){ - showInitError("Unable to create key in registry."); + crash("Unable to create key in registry."); } else { keyOpenError = ERROR_SUCCESS; @@ -202,7 +202,7 @@ static void setGamePathInRegistry() { } if (keyOpenError != ERROR_SUCCESS){ - showInitError("Unable to open registry."); + crash("Unable to open registry."); } else { DWORD dataSize = (strlen(dataDir) + 1) * sizeof(char); @@ -211,12 +211,11 @@ static void setGamePathInRegistry() { } RegCloseKey(key); } - //SDL_free(dataDir); // not needed in sdl3 } #endif //TODO handle this for Linux/Mac } -int main(int argc, char *argv[]){ +int main(int argc, char *argv[]){ char msg[512]; loadLanguageMetadata(); //there will be a segfault on fclose if I don't move it here @@ -281,7 +280,8 @@ int main(int argc, char *argv[]){ if (!conf.gameFolder.empty()) if (chdir(conf.gameFolder.c_str()) != 0){ - showInitError(std::string("Unable to switch into gameFolder ") + conf.gameFolder); + snprintf(msg, sizeof msg, "Unable to switch into gameFolder %s", conf.gameFolder); + crash(msg); return 0; } @@ -296,7 +296,6 @@ int main(int argc, char *argv[]){ snprintf(msg, sizeof msg, "Error initializing SDL_ttf: %s", SDL_GetError()); crash(msg); SDL_Quit(); - return 0; } @@ -355,8 +354,7 @@ int main(int argc, char *argv[]){ #ifndef STEAM /* Add controller bindings from embedded controller DB */ - SDL_IOStream *controllerDB = SDL_IOFromConstMem(assets_gamecontrollerdb_txt, - assets_gamecontrollerdb_txt_len); + SDL_IOStream *controllerDB = SDL_IOFromConstMem(assets_gamecontrollerdb_txt, assets_gamecontrollerdb_txt_len); SDL_AddGamepadMappingsFromIO(controllerDB, 1); #endif @@ -396,8 +394,7 @@ int main(int argc, char *argv[]){ SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, conf.windowTitle.c_str(), "The RGSS script seems to be stuck and OneShot: Sunshine will now force quit", win); if (!rtData.rgssErrorMsg.empty()){ - Debug() << rtData.rgssErrorMsg; - SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, conf.windowTitle.c_str(), rtData.rgssErrorMsg.c_str(), win); + crash(rtData.rgssErrorMsg.c_str()); } /* Clean up any remainin events */