diff --git a/src/alstream.cpp b/src/alstream.cpp index 46bb3fd..6910f27 100644 --- a/src/alstream.cpp +++ b/src/alstream.cpp @@ -21,6 +21,7 @@ #include "alstream.h" +#include "meow.h" #include "sharedstate.h" #include "eventthread.h" #include "filesystem.h" @@ -233,6 +234,7 @@ void ALStream::openSource(const std::string &filename){ char buf[512]; snprintf(buf, sizeof(buf), "Unable to decode audio stream: %s: %s", filename.c_str(), handler.errorMsg.c_str()); + crash(buf); Debug() << buf; } diff --git a/src/bitmap.cpp b/src/bitmap.cpp index e553f64..a7fc333 100644 --- a/src/bitmap.cpp +++ b/src/bitmap.cpp @@ -36,6 +36,7 @@ #include "transform.h" #include "exception.h" +#include "meow.h" #include "sharedstate.h" #include "glstate.h" #include "texpool.h" @@ -222,13 +223,14 @@ struct BitmapOpenHandler : FileSystem::OpenHandler{ Bitmap::Bitmap(const char *filename){ BitmapOpenHandler handler; + char msg[1024]; shState->fileSystem().openRead(handler, filename); SDL_Surface *imgSurf = handler.surf; - if (!imgSurf) - throw Exception(Exception::SDLError, "Error loading image '%s': %s", - filename, SDL_GetError()); - + if (!imgSurf){ + snprintf(msg, sizeof msg, "Error loading image '%s': %s", filename, SDL_GetError()); + throw Exception(Exception::SDLError, msg); + } p->ensureFormat(imgSurf, SDL_PIXELFORMAT_ABGR8888); if (imgSurf->w > glState.caps.maxTexSize || imgSurf->h > glState.caps.maxTexSize){ @@ -262,8 +264,10 @@ Bitmap::Bitmap(const char *filename){ } Bitmap::Bitmap(int width, int height){ - if (width <= 0 || height <= 0) - throw Exception(Exception::RGSSError, "failed to create bitmap"); + if (width <= 0 || height <= 0){ + crash("failed to create bitmap"); + throw Exception(Exception::RGSSError, "failed to create bitmap"); + } TEXFBO tex = shState->texPool().request(width, height); diff --git a/src/etc.cpp b/src/etc.cpp index b0e4f93..d4df041 100644 --- a/src/etc.cpp +++ b/src/etc.cpp @@ -23,6 +23,7 @@ #include "serial-util.h" #include "exception.h" +#include "meow.h" // this file doesn't exist, idk what to do if it, so i'll comment it. // #include @@ -102,8 +103,10 @@ void Color::serialize(char *buffer) const{ } Color *Color::deserialize(const char *data, int len){ - if (len != 32) + if (len != 32){ + crash("Color: Serialized data invalid"); throw Exception(Exception::ArgumentError, "Color: Serialized data invalid"); + } Color *c = new Color(); @@ -221,8 +224,10 @@ void Tone::serialize(char *buffer) const{ } Tone *Tone::deserialize(const char *data, int len){ - if (len != 32) + if (len != 32){ + crash("Tone: Serialized data invalid"); throw Exception(Exception::ArgumentError, "Tone: Serialized data invalid"); + } Tone *t = new Tone(); @@ -352,8 +357,10 @@ void Rect::serialize(char *buffer) const{ } Rect *Rect::deserialize(const char *data, int len){ - if (len != 16) + if (len != 16){ + crash("Rect: Serialized data invalid"); throw Exception(Exception::ArgumentError, "Rect: Serialized data invalid"); + } Rect *r = new Rect(); diff --git a/src/filesystem.cpp b/src/filesystem.cpp index 0371673..e95c8b9 100644 --- a/src/filesystem.cpp +++ b/src/filesystem.cpp @@ -54,7 +54,7 @@ struct SDLRWIoContext{ filename(filename) { if (!ops) - crash("Failed to open file", 0); + crash("Failed to open file"); throw Exception(Exception::SDLError, "Failed to open file: %s", SDL_GetError()); } diff --git a/src/gl-debug.cpp b/src/gl-debug.cpp index a19d7c5..d27a5f4 100644 --- a/src/gl-debug.cpp +++ b/src/gl-debug.cpp @@ -39,7 +39,7 @@ struct GLDebugLoggerPrivate{ void writeTimestamp(){ time(×tamp); - *stream << "[GLDEBUG " << ctime(×tamp) << "]"; + *stream << "[GLDEBUG | " << ctime(×tamp) << "]"; } void writeLine(const char *line){ diff --git a/src/main.cpp b/src/main.cpp index 18285d4..c16f7a0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -75,6 +75,7 @@ int rgssThreadFun(void *userdata){ RGSSThreadData *threadData = static_cast(userdata); const Config &conf = threadData->config; SDL_Window *win = threadData->window; + char msg[512]; SDL_GLContext glCtx; /* Setup GL context */ @@ -87,7 +88,9 @@ int rgssThreadFun(void *userdata){ glCtx = SDL_GL_CreateContext(win); if (!glCtx){ - rgssThreadError(threadData, std::string("[rgssThreadFun] Error creating context: ") + SDL_GetError()); + snprintf(msg, sizeof msg, "Error creating context: %s", SDL_GetError()); + crash(msg); + rgssThreadError(threadData, std::string(msg)); return 0; } @@ -123,7 +126,8 @@ int rgssThreadFun(void *userdata){ ALCcontext *alcCtx = alcCreateContext(threadData->alcDev, 0); if (!alcCtx){ - rgssThreadError(threadData, "[rgssThreadFun] Error creating OpenAL context"); + crash("Error creating OpenAL context"); + rgssThreadError(threadData, "Error creating OpenAL context"); SDL_GL_DestroyContext(glCtx); return 0; @@ -213,6 +217,7 @@ static void setGamePathInRegistry() { //TODO handle this for Linux/Mac } int main(int argc, char *argv[]){ + char msg[512]; loadLanguageMetadata(); //there will be a segfault on fclose if I don't move it here SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0"); @@ -230,19 +235,20 @@ int main(int argc, char *argv[]){ /* initialize SDL first */ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMEPAD) == false){ - showInitError(std::string("Error initializing SDL: ") + SDL_GetError()); + snprintf(msg, sizeof msg, "Error initializing SDL: %s", SDL_GetError()); + crash(msg); return 0; } #ifdef STEAM if (!STEAMSHIM_init()){ - showInitError("Could not initialize Steamworks API"); + crash("Could not initialize Steamworks API"); return 0; } #endif if (!EventThread::allocUserEvents()){ - showInitError("Error allocating SDL user events"); + crash("Error allocating SDL user events"); return 0; } @@ -279,14 +285,16 @@ int main(int argc, char *argv[]){ conf.windowTitle = conf.game.title; if (TTF_Init() == false){ - showInitError(std::string("Error initializing SDL_ttf: ") + SDL_GetError()); + snprintf(msg, sizeof msg, "Error initializing SDL_ttf: %s", SDL_GetError()); + crash(msg); SDL_Quit(); return 0; } if (Sound_Init() == false){ - showInitError(std::string("Error initializing SDL_sound: ") + Sound_GetError()); + snprintf(msg, sizeof msg, "Error initializing SDL_sound: %s", Sound_GetError()); + crash(msg); TTF_Quit(); SDL_Quit(); @@ -305,7 +313,8 @@ int main(int argc, char *argv[]){ SDL_SetWindowFullscreen(win, true); if (!win){ - showInitError(std::string("Error creating window: ") + SDL_GetError()); + snprintf(msg, sizeof msg, "Error creating window: %s", SDL_GetError()); + crash(msg); return 0; } @@ -320,7 +329,7 @@ int main(int argc, char *argv[]){ ALCdevice *alcDev = alcOpenDevice(0); if (!alcDev){ - showInitError("Error opening OpenAL device"); + crash("Error opening OpenAL device"); SDL_DestroyWindow(win); TTF_Quit(); SDL_Quit(); diff --git a/src/meow.cpp b/src/meow.cpp index ab793ef..7583dcf 100644 --- a/src/meow.cpp +++ b/src/meow.cpp @@ -6,6 +6,7 @@ #include #include #include "meow.h" +#include "eventthread.h" #include "config.h" #include #include @@ -19,7 +20,7 @@ #ifdef __LINUX__ #include - #include + #include "xdg-user-dir-lookup.h" #endif @@ -28,13 +29,14 @@ SDL_MessageBoxButtonData buttons[] = { { SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT, 2, "No" } }; -int crash(const char* reason, int exit_code){ - const Config conf; +void crash(const char* reason){ + char msg[1024]; + snprintf(msg, sizeof msg, "Error occured! Error message: %s\n\n Want to create a crash log? You can share the crash log with the developers and help resolve the issue.", reason); SDL_MessageBoxData messageboxdata = { .flags = SDL_MESSAGEBOX_ERROR, .window = NULL, - .title = "Crashdump", - .message = "Error occured! Want to create a crash log?", + .title = "Crashlog", + .message = msg, .numbuttons = SDL_arraysize(buttons), .buttons = buttons, .colorScheme = NULL @@ -48,6 +50,7 @@ int crash(const char* reason, int exit_code){ if(buttonid == 1){ std::ofstream out; + const Config conf; time_t mtime = time(NULL); struct tm *now = localtime(&mtime); std::string time = std::to_string(now->tm_hour) + "." + std::to_string(now->tm_min) + "." + std::to_string(now->tm_sec); @@ -81,7 +84,6 @@ int crash(const char* reason, int exit_code){ out << "customDataPath: " << conf.customDataPath << std::endl; out << "commonDataPath: " << conf.commonDataPath << std::endl; out << "" << std::endl; - out << "Ruby version: " << rb_gv_get("ruby_version") << std::endl; const int sdlcompiled = SDL_VERSION; const int sdllinked = SDL_GetVersion(); @@ -91,20 +93,16 @@ int crash(const char* reason, int exit_code){ out << "SDL_sound(compiled) version: " << SDL_SOUND_MAJOR_VERSION << "." << SDL_IMAGE_MINOR_VERSION << "." << SDL_IMAGE_MICRO_VERSION << std::endl; out << "SDL_TTF(compiled) version: " << SDL_TTF_MAJOR_VERSION << "." << SDL_TTF_MINOR_VERSION << "." << SDL_TTF_MICRO_VERSION << std::endl; - out << "Detected OS: " << SDL_GetPlatform() << std::endl; + //out << "Detected OS: " << SDL_GetPlatform() << std::endl; #ifdef __LINUX__ out << "GTK(compiled) version: " << GTK_MAJOR_VERSION << "." << GTK_MINOR_VERSION << "." << GTK_MICRO_VERSION << std::endl; + out << "Desktop enviroment(XDG_CURRENT_DESKTOP): " << getenv("XDG_CURRENT_DESKTOP") << std::endl; #endif out << "ZLib version: " << ZLIB_VERSION << std::endl; - out << "OpenAL version: " << alGetString(AL_VERSION) << std::endl; - out << "Boost versino: " << BOOST_VERSION / 100000 << "." << BOOST_VERSION / 100 % 1000 << "." << BOOST_VERSION % 100 << std::endl; - - //out << "PhysFS version: " << PHYSFS_Version << std::endl; - out << "Pixman version: " << PIXMAN_VERSION_STRING << std::endl; out.close(); @@ -112,6 +110,4 @@ int crash(const char* reason, int exit_code){ printf("[CRASHLOG] Failed to write crashdump file\n"); } } - - return exit_code; } diff --git a/src/meow.h b/src/meow.h index d919f70..b48503a 100644 --- a/src/meow.h +++ b/src/meow.h @@ -1 +1 @@ -int crash(const char* reason, int exit_code); +void crash(const char* reason); diff --git a/src/shader.cpp b/src/shader.cpp index d104656..03afdf7 100644 --- a/src/shader.cpp +++ b/src/shader.cpp @@ -55,6 +55,7 @@ #include "blurV.vert.xxd" #include "obscured.frag.xxd" +#include "meow.h" #define INIT_SHADER(vert, frag, name) \ { \ @@ -140,7 +141,8 @@ static void setupShaderSource(GLuint shader, GLenum type, const unsigned char *b void Shader::init(const unsigned char *vert, int vertSize, const unsigned char *frag, int fragSize, const char *vertName, const char *fragName, const char *programName) { GLint success; - + char msg[512]; + /* Compile vertex shader */ setupShaderSource(vertShader, GL_VERTEX_SHADER, vert, vertSize); gl.CompileShader(vertShader); @@ -149,7 +151,9 @@ void Shader::init(const unsigned char *vert, int vertSize, const unsigned char * if (!success){ printShaderLog(vertShader); - throw Exception(Exception::MKXPError, "GLSL: An error occured while compiling vertex shader '%s' in program '%s'", vertName, programName); + snprintf(msg, sizeof msg, "GLSL: An error occured while compiling vertex shader '%s' in program '%s'", vertName, programName); + crash(msg); + throw Exception(Exception::MKXPError, msg); } /* Compile fragment shader */ @@ -160,7 +164,9 @@ void Shader::init(const unsigned char *vert, int vertSize, const unsigned char * if (!success){ printShaderLog(fragShader); - throw Exception(Exception::MKXPError, "GLSL: An error occured while compiling fragment shader '%s' in program '%s'", fragName, programName); + snprintf(msg, sizeof msg, "GLSL: An error occured while compiling fragment shader '%s' in program '%s'", fragName, programName); + crash(msg); + throw Exception(Exception::MKXPError, msg); } /* Link shader program */ @@ -177,7 +183,9 @@ void Shader::init(const unsigned char *vert, int vertSize, const unsigned char * if (!success){ printProgramLog(program); - throw Exception(Exception::MKXPError, "GLSL: An error occured while linking program '%s' (vertex '%s', fragment '%s')", programName, vertName, fragName); + snprintf(msg, sizeof msg, "GLSL: An error occured while linking program '%s' (vertex '%s', fragment '%s')", programName, vertName, fragName); + crash(msg); + throw Exception(Exception::MKXPError, msg); } }