crash() & close game on ruby error

This commit is contained in:
ZakatTeamI2P 2026-05-27 17:48:30 +04:00
parent cd2aa2e446
commit d6a845b36b
4 changed files with 27 additions and 15 deletions

View File

@ -30,6 +30,7 @@
#include "graphics.h" #include "graphics.h"
#include "audio.h" #include "audio.h"
#include "boost-hash.h" #include "boost-hash.h"
#include "meow.h"
#include <ruby.h> #include <ruby.h>
#include <ruby/encoding.h> #include <ruby/encoding.h>
@ -524,10 +525,10 @@ static void showExc(VALUE exc, const BacktraceData &btData){
file.resize(strlen(file.c_str())); file.resize(strlen(file.c_str()));
file = btData.scriptNames.value(file, file); file = btData.scriptNames.value(file, file);
std::string ms(640, '\0'); char ms[640];
snprintf(&ms[0], ms.size(), "Script '%s' line %s: %s occured.\n\n%s", file.c_str(), line, RSTRING_PTR(name), RSTRING_PTR(msg)); snprintf(&ms[0], 640, "Script '%s' line %s: %s occured.\n\n%s", file.c_str(), line, RSTRING_PTR(name), RSTRING_PTR(msg));
crash(ms);
showMsg(ms); exit(0);
} }
static void mriBindingExecute(){ static void mriBindingExecute(){

View File

@ -9,11 +9,9 @@
#include "config.h" #include "config.h"
#include "debugwriter.h" #include "debugwriter.h"
#include "pipe.h" #include "pipe.h"
#include "meow.h"
// #include "oldimpls/include.h"
static void showInitError(const std::string &msg){ static void showInitError(const std::string &msg){
Debug() << msg;
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Sunshine Error", msg.c_str(), 0); SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Sunshine Error", msg.c_str(), 0);
} }
@ -30,6 +28,7 @@ static bool readMessage(Pipe &ipc, char *buf, size_t size){
} }
int screenMain(Config &conf){ int screenMain(Config &conf){
char msg[512];
const SDL_Color colorKey = {0x00, 0xFF, 0x00, 0xFF}; const SDL_Color colorKey = {0x00, 0xFF, 0x00, 0xFF};
const SDL_Color black = {0x00, 0x00, 0x00, 0xFF}; const SDL_Color black = {0x00, 0x00, 0x00, 0xFF};
@ -39,7 +38,8 @@ int screenMain(Config &conf){
win = SDL_CreateWindow("The Journal", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SDL_WINDOW_RESIZABLE | SDL_WINDOW_TRANSPARENT); win = SDL_CreateWindow("The Journal", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SDL_WINDOW_RESIZABLE | SDL_WINDOW_TRANSPARENT);
if (!win){ if (!win){
showInitError(std::string("Error creating window: ") + SDL_GetError()); snprintf(msg, sizeof msg, "Error creating window: %s", SDL_GetError());
crash(msg);
return 0; return 0;
} }

View File

@ -27,6 +27,7 @@
#include "serial-util.h" #include "serial-util.h"
#include "exception.h" #include "exception.h"
#include "util.h" #include "util.h"
#include "meow.h"
/* Init normally */ /* Init normally */
Table::Table(int x, int y /*= 1*/, int z /*= 1*/) Table::Table(int x, int y /*= 1*/, int z /*= 1*/)
@ -112,8 +113,10 @@ void Table::serialize(char *buffer) const{
Table *Table::deserialize(const char *data, int len){ Table *Table::deserialize(const char *data, int len){
if (len < 20) if (len < 20){
crash("Marshal: Table: bad file format");
throw Exception(Exception::RGSSError, "Marshal: Table: bad file format"); throw Exception(Exception::RGSSError, "Marshal: Table: bad file format");
}
readInt32(&data); readInt32(&data);
int x = readInt32(&data); int x = readInt32(&data);
@ -121,11 +124,15 @@ Table *Table::deserialize(const char *data, int len){
int z = readInt32(&data); int z = readInt32(&data);
int size = readInt32(&data); int size = readInt32(&data);
if (size != x*y*z) if (size != x*y*z){
crash("Marshal: Table: bad file format");
throw Exception(Exception::RGSSError, "Marshal: Table: bad file format"); throw Exception(Exception::RGSSError, "Marshal: Table: bad file format");
}
if (len != 20 + x*y*z*2) if (len != 20 + x*y*z*2){
crash("Marshal: Table: bad file format");
throw Exception(Exception::RGSSError, "Marshal: Table: bad file format"); throw Exception(Exception::RGSSError, "Marshal: Table: bad file format");
}
Table *t = new Table(x, y, z); Table *t = new Table(x, y, z);
memcpy(dataPtr(t->data), data, sizeof(int16_t)*size); memcpy(dataPtr(t->data), data, sizeof(int16_t)*size);

View File

@ -25,6 +25,7 @@
#include "glstate.h" #include "glstate.h"
#include "boost-hash.h" #include "boost-hash.h"
#include "debugwriter.h" #include "debugwriter.h"
#include "meow.h"
#include <list> #include <list>
#include <utility> #include <utility>
@ -96,7 +97,7 @@ TexPool::~TexPool(){
TEXFBO TexPool::request(int width, int height){ TEXFBO TexPool::request(int width, int height){
CacheNode cnode; CacheNode cnode;
Size size(width, height); Size size(width, height);
char msg[512];
/* See if we can statisfy request from cache */ /* See if we can statisfy request from cache */
CNodeList &bucket = p->poolHash[size]; CNodeList &bucket = p->poolHash[size];
@ -116,8 +117,11 @@ TEXFBO TexPool::request(int width, int height){
} }
int maxSize = glState.caps.maxTexSize; int maxSize = glState.caps.maxTexSize;
if (width > maxSize || height > maxSize) if (width > maxSize || height > maxSize){
throw Exception(Exception::MKXPError, "Texture dimensions [%d, %d] exceed hardware capabilities", width, height); snprintf(msg, sizeof msg, "Texture dimensions [%d, %d] exceed hardware capabilities", width, height);
crash(msg);
throw Exception(Exception::MKXPError, msg);
}
/* Nope, create it instead */ /* Nope, create it instead */
TEXFBO::init(cnode.obj); TEXFBO::init(cnode.obj);