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

View file

@ -9,11 +9,9 @@
#include "config.h"
#include "debugwriter.h"
#include "pipe.h"
// #include "oldimpls/include.h"
#include "meow.h"
static void showInitError(const std::string &msg){
Debug() << msg;
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){
char msg[512];
const SDL_Color colorKey = {0x00, 0xFF, 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);
if (!win){
showInitError(std::string("Error creating window: ") + SDL_GetError());
snprintf(msg, sizeof msg, "Error creating window: %s", SDL_GetError());
crash(msg);
return 0;
}

View file

@ -27,6 +27,7 @@
#include "serial-util.h"
#include "exception.h"
#include "util.h"
#include "meow.h"
/* Init normally */
Table::Table(int x, int y /*= 1*/, int z /*= 1*/)
@ -112,20 +113,26 @@ void Table::serialize(char *buffer) const{
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");
}
readInt32(&data);
int x = readInt32(&data);
int y = readInt32(&data);
int z = 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");
}
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");
}
Table *t = new Table(x, y, z);
memcpy(dataPtr(t->data), data, sizeof(int16_t)*size);

View file

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