This commit is contained in:
ZakatTeamI2P 2026-05-27 16:26:22 +04:00
parent a6d5865b4b
commit 3a9f437e83
9 changed files with 65 additions and 39 deletions

View file

@ -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;
}

View file

@ -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);

View file

@ -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 <SDL3/SDL_types.h>
@ -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();

View file

@ -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());
}

View file

@ -39,7 +39,7 @@ struct GLDebugLoggerPrivate{
void writeTimestamp(){
time(&timestamp);
*stream << "[GLDEBUG " << ctime(&timestamp) << "]";
*stream << "[GLDEBUG | " << ctime(&timestamp) << "]";
}
void writeLine(const char *line){

View file

@ -75,6 +75,7 @@ int rgssThreadFun(void *userdata){
RGSSThreadData *threadData = static_cast<RGSSThreadData*>(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();

View file

@ -6,6 +6,7 @@
#include <SDL3_sound/SDL_sound.h>
#include <SDL3_ttf/SDL_ttf.h>
#include "meow.h"
#include "eventthread.h"
#include "config.h"
#include <stdio.h>
#include <time.h>
@ -19,7 +20,7 @@
#ifdef __LINUX__
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#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;
}

View file

@ -1 +1 @@
int crash(const char* reason, int exit_code);
void crash(const char* reason);

View file

@ -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);
}
}