From 26d056d92450be7d4b1b40635a4f5534c6ecbf78 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Sun, 23 Jun 2013 18:50:10 +0200 Subject: [PATCH] Slightly more sensible error/msgbox handling --- Aquaria/AquariaMenuItem.cpp | 11 +--------- Aquaria/Continuity.cpp | 2 +- Aquaria/DSQ.cpp | 11 +++++----- Aquaria/Game.cpp | 5 ++--- Aquaria/GameplayVariables.cpp | 3 +-- Aquaria/ScriptInterface.cpp | 4 ++-- Aquaria/StringBank.cpp | 3 +++ BBGE/Base.cpp | 33 ++++++++++++++--------------- BBGE/Base.h | 6 ++---- BBGE/Core.cpp | 40 +++++++++-------------------------- BBGE/Core.h | 2 -- BBGE/SkeletalSprite.cpp | 3 +-- BBGE/StateManager.cpp | 2 +- BBGE/Texture.cpp | 2 -- BBGE/Vector.cpp | 4 ++-- 15 files changed, 48 insertions(+), 83 deletions(-) diff --git a/Aquaria/AquariaMenuItem.cpp b/Aquaria/AquariaMenuItem.cpp index 71d8689..c288058 100644 --- a/Aquaria/AquariaMenuItem.cpp +++ b/Aquaria/AquariaMenuItem.cpp @@ -569,8 +569,7 @@ void AquariaKeyConfig::onUpdate(float dt) if (!ai) { - errorLog("Could not find actionInput: " + actionInputName); - exit(-1); + exit_error("Could not find actionInput: " + actionInputName); } switch(inputSetType) { @@ -589,14 +588,6 @@ void AquariaKeyConfig::onUpdate(float dt) } } - /* - if (k == 0) - { - errorLog("AquariaKeyConfig::onUpdate"); - exit(-1); - } - */ - int *value = 0; if (inputSetType == INPUTSET_OTHER) diff --git a/Aquaria/Continuity.cpp b/Aquaria/Continuity.cpp index 71d0a6d..3dcd985 100644 --- a/Aquaria/Continuity.cpp +++ b/Aquaria/Continuity.cpp @@ -2659,7 +2659,7 @@ void Continuity::loadFile(int slot) if (startData->Attribute("mod")) { #ifdef AQUARIA_DEMO - exit(-1); + exit_error("The demo version does not support loading savegames from mods, sorry."); #else dsq->mod.load(startData->Attribute("mod")); #endif diff --git a/Aquaria/DSQ.cpp b/Aquaria/DSQ.cpp index cfa6aca..2d20ce1 100644 --- a/Aquaria/DSQ.cpp +++ b/Aquaria/DSQ.cpp @@ -922,12 +922,14 @@ This build is not yet final, and as such there are a couple things lacking. They // steam gets inited in here Core::init(); - // steam callbacks are inited here - dsq->continuity.init(); + dsq->continuity.stringBank.load(); vars = &v; v.load(); + // steam callbacks are inited here + dsq->continuity.init(); + // do copy stuff #ifdef BBGE_BUILD_UNIX std::string fn; @@ -997,8 +999,7 @@ This build is not yet final, and as such there are a couple things lacking. They { std::ostringstream os; os << "Aspect ratio for resolution [" << user.video.resx << ", " << user.video.resy << "] not supported."; - errorLog(os.str()); - exit(0); + exit_error(os.str()); } setFilter(dsq_filter); @@ -1041,7 +1042,7 @@ This build is not yet final, and as such there are a couple things lacking. They if (!createWindow(user.video.resx, user.video.resy, user.video.bits, user.video.full, "Aquaria")) #endif { - msg("Failed to create window"); + exit_error("Failed to create window"); return; } diff --git a/Aquaria/Game.cpp b/Aquaria/Game.cpp index 3270fbc..1520c8d 100644 --- a/Aquaria/Game.cpp +++ b/Aquaria/Game.cpp @@ -2432,8 +2432,7 @@ void Game::loadEntityTypeList() std::string line; if(!in) { - core->messageBox(dsq->continuity.stringBank.get(2008), dsq->continuity.stringBank.get(2016)); - exit(1); + exit_error(dsq->continuity.stringBank.get(2008).c_str()); } while (std::getline(in, line)) { @@ -5213,7 +5212,7 @@ bool Game::loadScene(std::string scene) } if (i == allowedMaps.size()) { - exit(-1); + exit_error("Demo version refuses to load this map, sorry."); } #endif diff --git a/Aquaria/GameplayVariables.cpp b/Aquaria/GameplayVariables.cpp index bd04c5d..8d7bfcd 100644 --- a/Aquaria/GameplayVariables.cpp +++ b/Aquaria/GameplayVariables.cpp @@ -27,8 +27,7 @@ void GameplayVariables::load() InStream inFile("data/variables.txt"); if(!inFile) { - core->messageBox(dsq->continuity.stringBank.get(2008), dsq->continuity.stringBank.get(2017)); - exit(1); + exit_error(dsq->continuity.stringBank.get(2017)); } std::string s; inFile >> s >> maxSlowSwimSpeed; diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index 856f1fb..cb51bf3 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -713,8 +713,8 @@ luaFunc(indexWarnInstance) luaFunc(panicHandler) { - errorLog(luaFormatStackInfo(L) + ": Lua PANIC: " + getString(L, -1)); - exit(1); + std::string err = luaFormatStackInfo(L) + ": Lua PANIC: " + getString(L, -1); + exit_error(err); } static bool findFile_helper(const char *rawname, std::string &fname) diff --git a/Aquaria/StringBank.cpp b/Aquaria/StringBank.cpp index d1d144f..abdbb8d 100644 --- a/Aquaria/StringBank.cpp +++ b/Aquaria/StringBank.cpp @@ -41,6 +41,9 @@ void StringBank::load() fname = localisePath(dsq->mod.getPath() + "stringbank.txt", dsq->mod.getPath()); _load(fname); } + + if(stringMap.empty()) + exit_error("Failed to load data/stringbank.txt"); } void StringBank::_load(const std::string &file) diff --git a/BBGE/Base.cpp b/BBGE/Base.cpp index 6feee42..b996122 100644 --- a/BBGE/Base.cpp +++ b/BBGE/Base.cpp @@ -291,8 +291,7 @@ bool exists(const std::string &f, bool makeFatal, bool skipVFS) if (makeFatal && !e) { - errorLog(std::string("Could not open [" + f + "]")); - exit(0); + exit_error("Could not open [" + f + "]"); } return e; @@ -316,10 +315,10 @@ void drawCircle(float radius, int stepSize) #endif } -void fatalError(const std::string &message) +void exit_error(const std::string &message) { - msg(message); - exit(0); + errorLog(message); + exit(1); } std::string parseCommand(const std::string &line, const std::string &command) @@ -424,8 +423,7 @@ void errorLog(const std::string &s) } else { - //msg("Core Not Initialized"); - //MessageBox(0, s.c_str(), "ErrorLog (Core Not Initalized)", MB_OK); + messageBox("Error!", s); } } @@ -775,17 +773,18 @@ std::vector getFileList(std::string path, std::string type, int par return list; } -std::string msg(const std::string &message) +void messageBox(const std::string& title, const std::string &msg) { - core->msg(message); - return message; -} - -void msgVector(const std::string &name, const Vector &vec) -{ - std::ostringstream os; - os << name << ": (" << vec.x <<", " << vec.y << ", " << vec.z << ")"; - msg (os.str()); +#ifdef BBGE_BUILD_WINDOWS + MessageBox (0,msg.c_str(),title.c_str(),MB_OK); +#elif defined(BBGE_BUILD_MACOSX) + cocoaMessageBox(title, msg); +#elif defined(BBGE_BUILD_UNIX) + // !!! FIXME: probably don't want the whole GTK+ dependency in here... + fprintf(stderr, "%s: %s\n", title.c_str(), msg.c_str()); +#else +#error Please define your platform. +#endif } Vector getNearestPointOnLine(Vector a, Vector b, Vector c) diff --git a/BBGE/Base.h b/BBGE/Base.h index 586a944..9c34277 100644 --- a/BBGE/Base.h +++ b/BBGE/Base.h @@ -257,11 +257,9 @@ bool isVectorInRect(const Vector &vec, const Vector &coord1, const Vector &coord std::string parseCommand(const std::string &line, const std::string &command); -std::string msg(const std::string &message); +void messageBox(const std::string &title, const std::string& msg); -void msgVector(const std::string &name, const Vector &vec); - -void fatalError(const std::string &message); +void exit_error(const std::string &message); unsigned hash(const std::string &string); diff --git a/BBGE/Core.cpp b/BBGE/Core.cpp index 9f68f9f..e1aa0d2 100644 --- a/BBGE/Core.cpp +++ b/BBGE/Core.cpp @@ -817,7 +817,7 @@ bool Core::getMetaState() void Core::errorLog(const std::string &s) { - messageBox("Message", s); + messageBox("Error!", s); debugLog(s); } @@ -827,16 +827,7 @@ void cocoaMessageBox(const std::string &title, const std::string &msg); void Core::messageBox(const std::string &title, const std::string &msg) { -#ifdef BBGE_BUILD_WINDOWS - MessageBox (0,msg.c_str(),title.c_str(),MB_OK); -#elif defined(BBGE_BUILD_MACOSX) - cocoaMessageBox(title, msg); -#elif defined(BBGE_BUILD_UNIX) - // !!! FIXME: probably don't want the whole GTK+ dependency in here... - fprintf(stderr, "%s: %s\n", title.c_str(), msg.c_str()); -#else -#error Please define your platform. -#endif + ::messageBox(title, msg); } void Core::debugLog(const std::string &s) @@ -1267,7 +1258,7 @@ void Core::init() if((SDL_Init(0))==-1) { - exit(0); + exit_error("Failed to init SDL"); } #endif @@ -1910,16 +1901,15 @@ bool Core::initGraphicsLibrary(int width, int height, bool fullscreen, int vsync { if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) { - errorLog(std::string("SDL Error: ") + std::string(SDL_GetError())); - exit(0); + exit_error(std::string("SDL Error: ") + std::string(SDL_GetError())); } #if BBGE_BUILD_OPENGL_DYNAMIC if (SDL_GL_LoadLibrary(NULL) == -1) { - errorLog(std::string("SDL_GL_LoadLibrary Error: ") + std::string(SDL_GetError())); + std::string err = std::string("SDL_GL_LoadLibrary Error: ") + std::string(SDL_GetError()); SDL_Quit(); - exit(0); + exit_error(err); } #endif } @@ -1943,9 +1933,8 @@ bool Core::initGraphicsLibrary(int width, int height, bool fullscreen, int vsync { std::ostringstream os; os << "Couldn't set resolution [" << width << "x" << height << "]\n" << SDL_GetError(); - errorLog(os.str()); SDL_Quit(); - exit(0); + exit_error(os.str()); } #if BBGE_BUILD_OPENGL_DYNAMIC @@ -1953,9 +1942,8 @@ bool Core::initGraphicsLibrary(int width, int height, bool fullscreen, int vsync { std::ostringstream os; os << "Couldn't load OpenGL symbols we need\n"; - errorLog(os.str()); SDL_Quit(); - exit(0); + exit_error(os.str()); } #endif } @@ -2625,13 +2613,6 @@ void Core::setDockIcon(const std::string &ident) { } -void Core::msg(const std::string &message) -{ -#ifdef BBGE_BUILD_WINDOWS - MessageBox(0, message.c_str(), "Message", MB_OK); -#endif -} - void Core::setMousePosition(const Vector &p) { Vector lp = core->mouse.position; @@ -4847,14 +4828,13 @@ void Core::setupFileAccess() debugLog("Init VFS..."); if(!ttvfs::checkCompat()) - exit(1); + exit_error("ttvfs not compatible"); vfs.AddArchiveLoader(new ttvfs::VFSZipArchiveLoader); if(!vfs.LoadFileSysRoot(false)) { - errorLog("Failed to setup file access"); - exit(1); + exit_error("Failed to setup file access"); } vfs.Prepare(); diff --git a/BBGE/Core.h b/BBGE/Core.h index 8e45ab3..1c514c9 100644 --- a/BBGE/Core.h +++ b/BBGE/Core.h @@ -1175,8 +1175,6 @@ public: void saveSizedScreenshotTGA(const std::string &filename, int sz, int crop34); void saveCenteredScreenshotTGA(const std::string &filename, int sz); - virtual void msg(const std::string &message); - bool minimized; std::string getEnqueuedJumpState(); int cullRadius; diff --git a/BBGE/SkeletalSprite.cpp b/BBGE/SkeletalSprite.cpp index c37744f..ea0a5d3 100644 --- a/BBGE/SkeletalSprite.cpp +++ b/BBGE/SkeletalSprite.cpp @@ -507,8 +507,7 @@ Animation* AnimationLayer::getCurrentAnimation() { std::ostringstream os; os << "skel: " << s->filenameLoaded << " currentAnimation: " << currentAnimation << " is out of range\n error in anim file?"; - errorLog(os.str()); - exit(-1); + exit_error(os.str()); return 0; } return &s->animations[currentAnimation]; diff --git a/BBGE/StateManager.cpp b/BBGE/StateManager.cpp index e82aefb..eb3195a 100644 --- a/BBGE/StateManager.cpp +++ b/BBGE/StateManager.cpp @@ -288,7 +288,7 @@ void StateManager::registerStateObject(StateObject *stateObject, const std::stri //getNameFromDerivedClassTypeName(c); if (stateObject->name.empty()) { - fatalError("StateManager::registerStateObject - Empty name."); + exit_error("StateManager::registerStateObject - Empty name."); } if (!stateObjects[stateObject->name]) diff --git a/BBGE/Texture.cpp b/BBGE/Texture.cpp index a15e69c..97cd22b 100644 --- a/BBGE/Texture.cpp +++ b/BBGE/Texture.cpp @@ -446,7 +446,6 @@ void Texture::loadPNG(const std::string &file) width = 64; height = 64; Texture::textureError = TEXERR_FILENOTFOUND; - //exit(1); return; } @@ -483,7 +482,6 @@ void Texture::loadPNG(const std::string &file) width = 64; height = 64; Texture::textureError = TEXERR_FILENOTFOUND; - //exit(1); } diff --git a/BBGE/Vector.cpp b/BBGE/Vector.cpp index 94eeb49..73b24bc 100644 --- a/BBGE/Vector.cpp +++ b/BBGE/Vector.cpp @@ -306,12 +306,12 @@ Vector VectorPath::getValue(float usePercent) if (!from && !target) { - msg ("returning first value"); + errorLog("returning first value"); return pathNodes[0].value; } else if (!from && target) { - msg("Unexpected Path node result (UPDATE: Could use current value as from?)"); + errorLog("Unexpected Path node result (UPDATE: Could use current value as from?)"); } else if (from && !target) {