From 5d5d6eb7488292b7f68b364865d1da75bafaa297 Mon Sep 17 00:00:00 2001 From: DepressedTWM Date: Fri, 14 Aug 2026 21:06:03 +0400 Subject: [PATCH] crash() improvement --- binding-mri/sunshine-binding.cpp | 2 +- src/meow.cpp | 98 +++++++++++++++----------------- src/meow.h | 1 + src/sunshine.h | 2 - 4 files changed, 49 insertions(+), 54 deletions(-) diff --git a/binding-mri/sunshine-binding.cpp b/binding-mri/sunshine-binding.cpp index 85ff52e..eccc259 100644 --- a/binding-mri/sunshine-binding.cpp +++ b/binding-mri/sunshine-binding.cpp @@ -11,7 +11,7 @@ #include "security.h" #include "eventthread.h" #include "sunshine.h" -bool is_privacy_crashdump_enabled = false; +#include "meow.h" static VALUE sunshine_get_crash_privacy(VALUE self) { return is_privacy_crashdump_enabled ? Qtrue : Qfalse; diff --git a/src/meow.cpp b/src/meow.cpp index 781d2ad..ae27013 100644 --- a/src/meow.cpp +++ b/src/meow.cpp @@ -47,7 +47,6 @@ #include #endif #include "crash.png.xxd" - using namespace std; static inline const char* glGetStringInt(GLenum name){ @@ -106,10 +105,6 @@ static void get_reason_and_solution(Exception::Type t) { } void crash(Exception::Type t, const char *fmt, ...) { - static char crash_message[1024]; - static const char* crash_reason = nullptr; - static const char* crash_possible_solution = nullptr; - va_list args; va_start(args, fmt); @@ -130,30 +125,27 @@ void crash(Exception::Type t, const char *fmt, ...) { } void crash_screen(SDL_Window* win){ - static char msg[1024] = ""; - static char msg1[1024] = ""; - static char msg2[1024] = ""; - static char msg3[1024] = ""; - static char msg4[1024] = ""; + // Skil Crash screen if failed initialize + static bool skip_crash_screen = false; //creating render SDL_Renderer* ren = SDL_CreateRenderer(win, NULL); if (ren == nullptr) { - WarnMsg("Failed to create crash sceen, please check if your device is too strong to run game: ", SDL_GetError()); + WarnMsg("Failed to create renderer, please check if your device is too strong to run game or report bug.Error Message: ", SDL_GetError()); + skip_crash_screen = true; } SDL_Surface* crash_img = IMG_Load_IO(SDL_IOFromConstMem(assets_crash_png, assets_crash_png_len), true); if (crash_img == nullptr) { - WarnMsg("Failed to create crash sceen, please check if your device is too strong to run game: ", SDL_GetError()); + WarnMsg("Failed to create surface, please check if your device is too strong to run game or report bug.Error Message: ", SDL_GetError()); + skip_crash_screen = true; } SDL_Texture* tex = SDL_CreateTextureFromSurface(ren, crash_img); SDL_DestroySurface(crash_img); if (tex == nullptr) { - WarnMsg("Failed to create crash sceen, please check if your device is too strong to run game: ", SDL_GetError()); + WarnMsg("Failed to create texture, please check if your device is too strong to run game or report bug.Error Message: ", SDL_GetError()); + skip_crash_screen = true; + }else{ + SDL_SetTextureScaleMode(tex, SDL_SCALEMODE_NEAREST); } - //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); //creating file and timestamp ofstream o; time_t timestamp; @@ -164,7 +156,6 @@ void crash_screen(SDL_Window* win){ } string file = "crash " + timeeeeee + ".txt"; std::erase(file, ':'); - 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()){ @@ -172,7 +163,7 @@ void crash_screen(SDL_Window* win){ o << "EXPEREMENTAL BUILD" << endl; #endif o << "VERSION: " << VERSION_STRING << endl; - o << "REASON: " << msg << endl; + o << "REASON: " << crash_message << endl; o << "[BOOST stacktrace()]" << endl << endl; o << boost::stacktrace::stacktrace() << endl; @@ -216,7 +207,6 @@ void crash_screen(SDL_Window* win){ } #elif android 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; @@ -241,7 +231,9 @@ void crash_screen(SDL_Window* win){ o << "[Hardware]" << endl; o << "number of logical CPU cores: " << SDL_GetNumLogicalCPUCores() << endl; o << "System RAM size: " << SDL_GetSystemRAM() << " MiB" << endl; - o << "L1 cache size: " << SDL_GetCPUCacheLineSize() << endl; + if(!is_privacy_crashdump_enabled){ + o << "L1 cache size: " << SDL_GetCPUCacheLineSize() << endl; + } o << endl; o << "[OpenGL]" << endl; @@ -259,38 +251,42 @@ void crash_screen(SDL_Window* win){ }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 - }; + if(!skip_crash_screen){ + 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; - } + 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, &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_RenderDebugText(ren, 10, 70, "If you are sure that the problem is not in your modifications,"); - SDL_RenderDebugText(ren, 10, 80, "your hands or in your device - please report the bug to the developers"); - SDL_RenderPresent(ren); + SDL_SetRenderDrawColor(ren, 0, 0, 0, 255); + SDL_RenderClear(ren); + SDL_RenderTexture(ren, tex, NULL, &dst); + SDL_SetRenderDrawColor(ren, 255, 255, 255, 255); + SDL_RenderDebugTextFormat(ren, 10, 10, "World machine crashed, crashdump created in game directory"); + SDL_RenderDebugTextFormat(ren, 10, 20, "%s", crash_message); + SDL_RenderDebugTextFormat(ren, 10, 30, "Possible reason: %s", crash_reason); + SDL_RenderDebugTextFormat(ren, 10, 40, "Possible solution: %s", crash_possible_solution); + SDL_RenderDebugTextFormat(ren, 10, 50, "Path: %s%s", SDL_GetCurrentDirectory(), file.c_str()); + SDL_RenderDebugTextFormat(ren, 10, 60, "Crashdump privacy: %s", is_privacy_crashdump_enabled ? "enabled" : "disabled"); + SDL_RenderDebugTextFormat(ren, 10, 70, "If you are sure that the problem is not in your modifications,"); + SDL_RenderDebugTextFormat(ren, 10, 80, "your hands or in your device - please report the bug to the developers"); + SDL_RenderPresent(ren); + } + SDL_DestroyTexture(tex); + SDL_DestroyRenderer(ren); } } diff --git a/src/meow.h b/src/meow.h index 504869a..5344b76 100644 --- a/src/meow.h +++ b/src/meow.h @@ -7,6 +7,7 @@ inline std::vector logs = {}; inline bool show_crash_sceen = false; +inline bool is_privacy_crashdump_enabled = false; inline bool is_ruby_initialized = false; inline char crash_message[1024] = ""; inline const char* crash_reason = "Unknown"; diff --git a/src/sunshine.h b/src/sunshine.h index 01ee6bc..f1ce81f 100644 --- a/src/sunshine.h +++ b/src/sunshine.h @@ -3,8 +3,6 @@ #include "bitmap.h" //помойка ебаная inline boost::chrono::high_resolution_clock::time_point startTime; - -extern bool is_privacy_crashdump_enabled; class Sunshine{ public: Sunshine();