diff --git a/assets/crash.png b/assets/crash.png index b6bb8dc..1b997e2 100644 Binary files a/assets/crash.png and b/assets/crash.png differ diff --git a/changelogs/0.1.2.txt b/changelogs/0.1.2.txt index 6aa245f..780e259 100644 --- a/changelogs/0.1.2.txt +++ b/changelogs/0.1.2.txt @@ -52,3 +52,5 @@ Documents path search code rewrited to crossplatform SDL functions. DEBUG SAVE bug fixed Added FreeBSD build script Fixed Office teleport bug +Added Crash Screen +Added In-Memory Log buffer diff --git a/src/debugwriter.h b/src/debugwriter.h index 85181b1..7ff0744 100644 --- a/src/debugwriter.h +++ b/src/debugwriter.h @@ -26,6 +26,7 @@ #include #include #include +#include "meow.h" #undef vsnprintf #undef snprintf @@ -69,6 +70,7 @@ public: #elif __EMSCRIPTEN__ emscripten_console_log(buf.str().c_str()); #else + logs.push_back(buf.str()); std::cout << buf.str() << "\n"; #endif } diff --git a/src/define.h b/src/define.h index f5d01bb..a1e06f8 100644 --- a/src/define.h +++ b/src/define.h @@ -8,10 +8,6 @@ #define unix_like 1 #endif -#if defined(SDL_PLATFORM_DOS) - #define dos 1 -#endif - #if defined(SDL_WINAPI_FAMILY_PHONE) || defined(SDL_PLATFORM_WINDOWS) || defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_WINGDK) #define windows 1 #endif diff --git a/src/gl-util.h b/src/gl-util.h index 112799c..4edbcdf 100644 --- a/src/gl-util.h +++ b/src/gl-util.h @@ -220,7 +220,7 @@ struct TEXFBO{ #define GL_CHECK() { \ GLenum e = gl.GetError(); \ if (e != GL_NO_ERROR) \ - printf("%s:%d -> %x\n", __FILE__, __LINE__, e); \ + Debug() << __FILE__ << ":" << __LINE__ "->" << e); \ } #endif // GLUTIL_H diff --git a/src/main.cpp b/src/main.cpp index d42ea2b..cc8068c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -213,9 +213,6 @@ static void setGamePathInRegistry() { //TODO handle this for Linux/Mac } int main(int argc, char *argv[]){ - #if dos - __djgpp_nearptr_enable(); - #endif startTime = boost::chrono::high_resolution_clock::now(); 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"); @@ -234,8 +231,6 @@ int main(int argc, char *argv[]){ SDL_SetHint(SDL_HINT_VITA_RESOLUTION, "1080"); #elif ps2 SFL_SetHint(SDL_HINT_PS2_GS_MODE, "NTSC"); - #elif dos - SDL_SetHint(SDL_HINT_DOS_ALLOW_DIRECT_FRAMEBUFFER, "1"); #endif /* initialize SDL first */ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMEPAD) == false){ diff --git a/src/meow.cpp b/src/meow.cpp index c9b4cbb..d764748 100644 --- a/src/meow.cpp +++ b/src/meow.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -16,8 +17,10 @@ #include "debugwriter.h" #include "define.h" #include -#include +#include #include +#include +#include #include #include #include @@ -47,9 +50,10 @@ #elif dos #include #endif - #include "crash.png.xxd" +using namespace std; + static inline const char* glGetStringInt(GLenum name){ return (const char*) gl.GetString(name); } @@ -89,123 +93,141 @@ void crash_screen(SDL_Window* win){ static char msg1[1024] = ""; static char msg2[1024] = ""; static char msg3[1024] = ""; + static char msg4[1024] = ""; + //creating render SDL_Renderer* ren = SDL_CreateRenderer(win, NULL); if (ren == nullptr) { - ErrorMsg("Failed to create crash sceen, please check if your device is too strong to run game: ", SDL_GetError()); + WarnMsg("Failed to create crash sceen, please check if your device is too strong to run game: ", SDL_GetError()); } SDL_Surface* crash_img = IMG_Load_IO(SDL_IOFromConstMem(assets_crash_png, assets_crash_png_len), true); if (crash_img == nullptr) { - ErrorMsg("Failed to create crash sceen, please check if your device is too strong to run game: ", SDL_GetError()); + WarnMsg("Failed to create crash sceen, please check if your device is too strong to run game: ", SDL_GetError()); } SDL_Texture* tex = SDL_CreateTextureFromSurface(ren, crash_img); SDL_DestroySurface(crash_img); if (tex == nullptr) { - ErrorMsg("Failed to create crash sceen, please check if your device is too strong to run game: ", SDL_GetError()); + WarnMsg("Failed to create crash sceen, please check if your device is too strong to run game: ", SDL_GetError()); } - SDL_SetRenderDrawColor(ren, 255, 255, 255, 255); + //stringsssssssssssss SDL_snprintf(msg, sizeof(msg), "Message: %s", crash_message); SDL_snprintf(msg1, sizeof(msg1), "Possible reason: %s", crash_reason); SDL_snprintf(msg2, sizeof(msg2), "Possible solution: %s", crash_possible_solution); - SDL_snprintf(msg3, sizeof(msg3), "Crashdump privacy: %s", is_privacy_crashdump_enabled); - - std::ofstream o; - 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); - o.open("crash_" + time + ".txt"); + SDL_snprintf(msg3, sizeof(msg3), "Crashdump privacy: %s", is_privacy_crashdump_enabled); + //creating file and timestamp + ofstream o; + time_t timestamp; + time(×tamp); + string timeeeeee(ctime(×tamp)); + if (!timeeeeee.empty() && timeeeeee.back() == '\n') { + timeeeeee.pop_back(); + } + string file = "crash " + timeeeeee + ".txt"; + SDL_snprintf(msg4, sizeof(msg4), "Path: %s%s", SDL_GetCurrentDirectory(), file.c_str()); + o.open(file); + + //collecting info and writing to crashdump if (o.is_open()){ - o << "REASON: " << msg << std::endl; - o << "[BOOST stacktrace()]" << std::endl; - o << boost::stacktrace::stacktrace() << std::endl; + o << "REASON: " << msg << endl; + o << "[BOOST stacktrace()]" << endl << endl; + o << boost::stacktrace::stacktrace() << endl; + o << "[LOG BUFFER]" << endl << endl; + for (const auto& s : logs) { + o << s << endl; + } + o << endl << "[VERSIONS OF LIBS]" << endl; const static int sdlcompiled = SDL_VERSION; const static int sdllinked = SDL_GetVersion(); - o << "SDL(compiled) version: " << SDL_VERSIONNUM_MAJOR(sdlcompiled) << "." << SDL_VERSIONNUM_MINOR(sdlcompiled) << "." << SDL_VERSIONNUM_MICRO(sdlcompiled) << std::endl; - o << "SDL(linked) version: " << SDL_VERSIONNUM_MAJOR(sdllinked) << "." << SDL_VERSIONNUM_MINOR(sdllinked) << "." << SDL_VERSIONNUM_MICRO(sdllinked) << std::endl; - o << "SDL_image(compiled) version: " << SDL_IMAGE_MAJOR_VERSION << "." << SDL_IMAGE_MINOR_VERSION << "." << SDL_IMAGE_MICRO_VERSION << std::endl; - o << "SDL_sound(compiled) version: " << SDL_SOUND_MAJOR_VERSION << "." << SDL_IMAGE_MINOR_VERSION << "." << SDL_IMAGE_MICRO_VERSION << std::endl; - o << "SDL_TTF(compiled) version: " << SDL_TTF_MAJOR_VERSION << "." << SDL_TTF_MINOR_VERSION << "." << SDL_TTF_MICRO_VERSION << std::endl; - o << "Ruby version: " << RUBY_API_VERSION_CODE << std::endl; - o << "ZLib version: " << ZLIB_VERSION << std::endl; - o << "OpenAL version: " << AL_VERSION << std::endl; - o << "Boost versino: " << BOOST_VERSION / 100000 << "." << BOOST_VERSION / 100 % 1000 << "." << BOOST_VERSION % 100 << std::endl; - o << "Pixman version: " << PIXMAN_VERSION_STRING << std::endl; - o << "[Platform specific]" << std::endl; + o << "SDL(compiled) version: " << SDL_VERSIONNUM_MAJOR(sdlcompiled) << "." << SDL_VERSIONNUM_MINOR(sdlcompiled) << "." << SDL_VERSIONNUM_MICRO(sdlcompiled) << endl; + o << "SDL(linked) version: " << SDL_VERSIONNUM_MAJOR(sdllinked) << "." << SDL_VERSIONNUM_MINOR(sdllinked) << "." << SDL_VERSIONNUM_MICRO(sdllinked) << endl; + o << "SDL_image(compiled) version: " << SDL_IMAGE_MAJOR_VERSION << "." << SDL_IMAGE_MINOR_VERSION << "." << SDL_IMAGE_MICRO_VERSION << endl; + o << "SDL_sound(compiled) version: " << SDL_SOUND_MAJOR_VERSION << "." << SDL_IMAGE_MINOR_VERSION << "." << SDL_IMAGE_MICRO_VERSION << endl; + o << "SDL_TTF(compiled) version: " << SDL_TTF_MAJOR_VERSION << "." << SDL_TTF_MINOR_VERSION << "." << SDL_TTF_MICRO_VERSION << endl; + o << "Ruby version: " << RUBY_API_VERSION_CODE << endl; + o << "ZLib version: " << ZLIB_VERSION << endl; + o << "OpenAL version: " << AL_VERSION << endl; + o << "Boost versino: " << BOOST_VERSION / 100000 << "." << BOOST_VERSION / 100 % 1000 << "." << BOOST_VERSION % 100 << endl; + o << "Pixman version: " << PIXMAN_VERSION_STRING << endl; + o << "[Platform specific]" << endl; try{ - o << "Detected OS: " << SDL_GetPlatform() << std::endl; + o << "Detected OS: " << SDL_GetPlatform() << endl; }catch(const std::exception& e){ - o << "Detected OS: " << e.what() << std::endl; + o << "Detected OS: " << e.what() << endl; } #ifdef unix_like if(SDL_getenv("XDG_CURRENT_DESKTOP") != nullptr){ - o << "Desktop enviroment(XDG_CURRENT_DESKTOP): " << SDL_getenv("XDG_CURRENT_DESKTOP") << std::endl; + o << "Desktop enviroment(XDG_CURRENT_DESKTOP): " << SDL_getenv("XDG_CURRENT_DESKTOP") << endl; } #elif android - o << "Android API version: " << android_get_device_api_level() << std::endl; - o << "External storage State: " << SDL_GetAndroidExternalStorageState() << std::endl; - o << "Internal storage path: " << SDL_GetAndroidInternalStoragePath() << std::endl; - o << "External Storage path: " << SDL_GetAndroidExternalStoragePath() << ats::endl; - o << "Cache path: " << SDL_GetAndroidCachePath() << std::endl; + o << "Android API version: " << android_get_device_api_level() << endl; + o << "External storage State: " << SDL_GetAndroidExternalStorageState() << endl; + o << "Internal storage path: " << SDL_GetAndroidInternalStoragePath() << endl; + o << "External Storage path: " << SDL_GetAndroidExternalStoragePath() << endl; + o << "Cache path: " << SDL_GetAndroidCachePath() << endl; if(!is_privacy_crashdump_enabled){ - o << "Is ChromeBook? " << SDL_IsChromebook() << std::endl; - o << "Is Phone? " << SDL_IsPhone() << std::endl; - o << "Is Tablet? " << SDL_IsTablet() << std::endl; - o << "Is Samsung DeX? " << SDL_IsDeXMode() << std::endl; - o << "Is TV? " << SDL_IsTV() << std::endl; - o << "Is Ubuntu Touch? " << SDL_IsUbuntuTouch() << std::endl; + o << "Is ChromeBook? " << SDL_IsChromebook() << endl; + o << "Is Phone? " << SDL_IsPhone() << endl; + o << "Is Tablet? " << SDL_IsTablet() << endl; + o << "Is Samsung DeX? " << SDL_IsDeXMode() << endl; + o << "Is TV? " << SDL_IsTV() << endl; + o << "Is Ubuntu Touch? " << SDL_IsUbuntuTouch() << endl; } #elif web - o << "Emscripten start address of the stack: " << emscripten_stack_get_base() << std::endl; - o << "Emscripten end address of the stack: " << emscripten_stack_get_end() << std::endl; - o << "Emscripten current stack pointer: " << emscripten_stack_get_current() << std::endl; - o << "Emscripten number of free bytes left on stack: " << emscripten_stack_get_free() << std::endl; + o << "Emscripten start address of the stack: " << emscripten_stack_get_base() << endl; + o << "Emscripten end address of the stack: " << emscripten_stack_get_end() << endl; + o << "Emscripten current stack pointer: " << emscripten_stack_get_current() << endl; + o << "Emscripten number of free bytes left on stack: " << emscripten_stack_get_free() << endl; #elif psp - o << "PSPdev MIPS Stack Trace: " << pspDebugGetStackTrace() << std::endl; - #elif dos - o << "DPMI virtual interrupt state: " << __dpmi_get_virtual_interrupt_state() << std::endl; - o << "DPMI selector increment value: " << __dpmi_get_selector_increment_value() << std::endl; - o << "DPMI coprocessor status: " << __dpmi_get_coprocessor_status() << std::endl; - o << "DPMI is 80387 processor?: " << _detect_80387() << std::endl; + o << "PSPdev MIPS Stack Trace: " << pspDebugGetStackTrace() << endl; #endif - o << "[Hardware]" << std::endl; - o << "number of logical CPU cores: " << SDL_GetNumLogicalCPUCores() << std::endl; - o << "System RAM size: " << SDL_GetSystemRAM() << " MiB" << std::endl; - o << "[Ruby]" << std::endl; - o << "Is GC was busy? " << rb_during_gc() << std::endl; - o << "[OpenGL]" << std::endl; + o << "[Hardware]" << endl; + o << "number of logical CPU cores: " << SDL_GetNumLogicalCPUCores() << endl; + o << "System RAM size: " << SDL_GetSystemRAM() << " MiB" << endl; + o << "[Ruby]" << endl; + o << "Is GC was busy? " << rb_during_gc() << endl; + o << "[OpenGL]" << endl; try{ - o << "GL Vendor: " << glGetStringInt(GL_VENDOR) << std::endl; - o << "GL Renderer: " << glGetStringInt(GL_RENDERER) << std::endl; - o << "GL Version: " << glGetStringInt(GL_VERSION) << std::endl; - o << "GLSL Version: " << glGetStringInt(GL_SHADING_LANGUAGE_VERSION) << std::endl; - o << "Shading language version: " << glGetStringInt(GL_SHADING_LANGUAGE_VERSION) << std::endl; - o << "GL Extensions: " << glGetStringInt(GL_EXTENSIONS) << std::endl; - }catch(const std::exception& e){ - o << "Crashed before OpenGL initialization: " << e.what() << std::endl; + o << "GL Vendor: " << glGetStringInt(GL_VENDOR) << endl; + o << "GL Renderer: " << glGetStringInt(GL_RENDERER) << endl; + o << "GL Version: " << glGetStringInt(GL_VERSION) << endl; + o << "GLSL Version: " << glGetStringInt(GL_SHADING_LANGUAGE_VERSION) << endl; + o << "Shading language version: " << glGetStringInt(GL_SHADING_LANGUAGE_VERSION) << endl; + o << "GL Extensions: " << glGetStringInt(GL_EXTENSIONS) << endl; + }catch(const exception& e){ + o << "Crashed before OpenGL initialization: " << e.what() << endl; } o.close(); }else{ WarnMsg("[CRASHLOG] Failed to write crashdump file"); } - - SDL_Event e; bool quit = false; + int texW = 100, texH = 100; + int winW = 0, winH = 0; + SDL_GetWindowSize(win, &winW, &winH); + SDL_FRect dst{ + (float)((winW - 100) / 2), + (float)((winH - 100) / 2), + (float)100, + (float)100 + }; + while (!quit) { while (SDL_PollEvent(&e)) { if (e.type == SDL_EVENT_QUIT) quit = true; } - + + SDL_SetRenderDrawColor(ren, 0, 0, 0, 255); SDL_RenderClear(ren); - SDL_RenderTexture(ren, tex, NULL, NULL); - + SDL_RenderTexture(ren, tex, NULL, &dst); + SDL_SetRenderDrawColor(ren, 255, 255, 255, 255); SDL_RenderDebugText(ren, 10, 10, "World machine crashed, crashdump created in game directory"); SDL_RenderDebugText(ren, 10, 20, msg); SDL_RenderDebugText(ren, 10, 30, msg1); SDL_RenderDebugText(ren, 10, 40, msg2); SDL_RenderDebugText(ren, 10, 50, msg3); - + SDL_RenderDebugText(ren, 10, 60, msg4); SDL_RenderPresent(ren); } } @@ -243,8 +265,6 @@ void WarnMsg(const char *fmt, ...) { SDL_vsnprintf(buf, (size_t)len + 1, fmt, args); va_end(args); - - if (SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING, "Warning", buf, NULL)) { - // TODO: error handling - } + Debug() << "[WARNMSG]" << buf; + SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING, "Warning", buf, NULL); } diff --git a/src/meow.h b/src/meow.h index dbcabe3..7853052 100644 --- a/src/meow.h +++ b/src/meow.h @@ -1,6 +1,10 @@ #pragma once #include "exception.h" #include +#include +#include + +inline std::vector logs = {}; inline bool show_crash_sceen = false; inline char crash_reason[1024] = "Unknown"; diff --git a/src/modloader.cpp b/src/modloader.cpp index 246152a..7b90b36 100644 --- a/src/modloader.cpp +++ b/src/modloader.cpp @@ -47,7 +47,7 @@ void ModLoader(){ if (ext == ".zip"){ int ok = PHYSFS_mount(full.c_str(), "/mod-storage", 0); if (!ok) { - crash(Exception::ModLoaderError, "PhysFS_mount failed: %s", PHYSFS_getLastError()); + //crash(Exception::ModLoaderError, "PhysFS_mount failed: %s", PHYSFS_getLastError()); } Debug() << "[MODLOADER] " << full; mod_list.push_back(full); diff --git a/src/security.cpp b/src/security.cpp index 53a6867..88d1901 100644 --- a/src/security.cpp +++ b/src/security.cpp @@ -2,7 +2,6 @@ #include "security.h" #include "meow.h" #include "debugwriter.h" -#include #include // this component is needed to protect users from mod attacks. @@ -32,7 +31,7 @@ void SecurityManagerInit(){ int n = sizeof(seccomplist) / sizeof(seccomplist[0]); for(int i = 0; i < n; ++i){ if(seccomp_rule_add(ctx, SCMP_ACT_KILL, seccomplist[i], 0) < 0) { - printf("seccomp_rule_add failed for %i", seccomplist[i]); + Debug() << "seccomp_rule_add failed for " << seccomplist[i]; } } diff --git a/src/vertex.cpp b/src/vertex.cpp index d816fc9..a5da5ba 100644 --- a/src/vertex.cpp +++ b/src/vertex.cpp @@ -24,13 +24,9 @@ #include -CVertex::CVertex() - : color(1, 1, 1, 1) -{} +CVertex::CVertex() : color(1, 1, 1, 1){} -Vertex::Vertex() - : color(1, 1, 1, 1) -{} +Vertex::Vertex() : color(1, 1, 1, 1){} #define o(type, mem) ((const GLvoid*) offsetof(type, mem)) diff --git a/src/viewport.cpp b/src/viewport.cpp index d2fcce8..9f22370 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -69,8 +69,7 @@ struct ViewportPrivate{ void updateRectCon(){ rectCon.Disconnect(); - rectCon = rect->valueChanged.Connect - (*this, &ViewportPrivate::onRectChange); + rectCon = rect->valueChanged.Connect(*this, &ViewportPrivate::onRectChange); } void recomputeOnScreen(){