Fix crash on exit

This commit is contained in:
John Alanbrook 2024-04-16 07:48:34 -05:00
parent bba9c3e90a
commit c368b81216
8 changed files with 31 additions and 34 deletions

View file

@ -58,6 +58,7 @@ endif
ifdef LEAK ifdef LEAK
CPPFLAGS += -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer -DLEAK CPPFLAGS += -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer -DLEAK
INFO := $(INFO)_leak
endif endif
ifeq ($(OPT),small) ifeq ($(OPT),small)

View file

@ -156,6 +156,7 @@ console.pprint = function(msg,lvl = 0) {
var file = "nofile"; var file = "nofile";
var line = 0; var line = 0;
console.rec(0,msg,file,line);
var caller = (new Error()).stack.split('\n')[2]; var caller = (new Error()).stack.split('\n')[2];
if (caller) { if (caller) {
@ -453,12 +454,12 @@ prosperon.touchrelease = function(touches){};
prosperon.touchmove = function(touches){}; prosperon.touchmove = function(touches){};
prosperon.clipboardpaste = function(str){}; prosperon.clipboardpaste = function(str){};
prosperon.quit = function(){ prosperon.quit = function(){
console.info(profile.printreport(profcache, "USE REPORT")); say(profile.printreport(profcache, "USE REPORT"));
console.info(profile.printreport(entityreport, "ENTITY REPORT")); say(profile.printreport(entityreport, "ENTITY REPORT"));
console.info("QUITTING"); console.info("QUITTING");
for (var i in debug.log.time) for (var i in debug.log.time)
console.warn(debug.log.time[i].map(x=>profile.ms(x))); say(debug.log.time[i].map(x=>profile.ms(x)));
}; };
global.mixin("scripts/input"); global.mixin("scripts/input");

View file

@ -101,14 +101,6 @@ JSValue js_getpropidx(JSValue v, uint32_t i)
return p; return p;
} }
JSValue gos2ref(gameobject **go)
{
JSValue array = JS_NewArray(js);
for (int i = 0; i < arrlen(go); i++)
js_setprop_num(array,i,JS_DupValue(js,go[i]->ref));
return array;
}
void js_setprop_str(JSValue obj, const char *prop, JSValue v) { JS_SetPropertyStr(js, obj, prop, v); } void js_setprop_str(JSValue obj, const char *prop, JSValue v) { JS_SetPropertyStr(js, obj, prop, v); }
JSValue js_getpropstr(JSValue v, const char *str) JSValue js_getpropstr(JSValue v, const char *str)
{ {
@ -1549,7 +1541,6 @@ void ffi_load() {
QJSGLOBALCLASS(dspsound); QJSGLOBALCLASS(dspsound);
QJSGLOBALCLASS(pshape); QJSGLOBALCLASS(pshape);
QJSGLOBALCLASS(performance); QJSGLOBALCLASS(performance);
QJSGLOBALCLASS(circle2d); QJSGLOBALCLASS(circle2d);
QJSGLOBALCLASS(poly2d); QJSGLOBALCLASS(poly2d);
QJSGLOBALCLASS(edge2d); QJSGLOBALCLASS(edge2d);
@ -1568,7 +1559,3 @@ void ffi_load() {
JS_FreeValue(js,globalThis); JS_FreeValue(js,globalThis);
} }
void ffi_stop()
{
}

View file

@ -120,7 +120,6 @@ JS_SetClassProto(js, js_##TYPE##_id, TYPE##_proto); \
#define countof(x) (sizeof(x)/sizeof((x)[0])) #define countof(x) (sizeof(x)/sizeof((x)[0]))
void ffi_load(); void ffi_load();
void ffi_stop();
JSValue vec22js(HMM_Vec2 v); JSValue vec22js(HMM_Vec2 v);
HMM_Vec2 js2vec2(JSValue v); HMM_Vec2 js2vec2(JSValue v);

View file

@ -35,17 +35,19 @@ void script_stop()
return; return;
#endif #endif
printf("FREEING CONTEXT\n"); printf("FREEING CONTEXT\n");
ffi_stop();
JS_FreeContext(js);
script_gc(); script_gc();
JS_FreeRuntime(rt);
JS_FreeContext(js);
js = NULL; js = NULL;
JS_FreeRuntime(rt);
rt = NULL; rt = NULL;
} }
void script_gc() { JS_RunGC(rt); } void script_gc() { JS_RunGC(rt); }
void js_stacktrace() { void js_stacktrace() {
if (!js) return;
#ifndef NDEBUG #ifndef NDEBUG
script_evalf("console.stack();"); script_evalf("console.stack();");
#endif #endif
@ -53,13 +55,19 @@ void js_stacktrace() {
void script_evalf(const char *format, ...) void script_evalf(const char *format, ...)
{ {
char fmtbuf[4096]; JSValue obj;
va_list args; va_list args;
va_start(args, format); va_start(args, format);
vsnprintf(fmtbuf, 4096, format, args); int len = vsnprintf(NULL, 0, format, args);
va_end(args); va_end(args);
JSValue obj = JS_Eval(js, fmtbuf, strlen(fmtbuf), "C eval", JS_EVAL_FLAGS); char *eval = malloc(len+1);
va_start(args, format);
vsnprintf(eval, len+1, format, args);
va_end(args);
obj = JS_Eval(js, eval, len, "C eval", JS_EVAL_FLAGS);
free(eval);
js_print_exception(obj); js_print_exception(obj);
JS_FreeValue(js,obj); JS_FreeValue(js,obj);
} }

View file

@ -114,17 +114,17 @@ void quickjs_set_dumpout(FILE *f)
#ifdef DUMP #ifdef DUMP
//#define DUMP_FREE //#define DUMP_FREE
#define DUMP_MEM #define DUMP_MEM
#define DUMP_CLOSURE //#define DUMP_CLOSURE
#define DUMP_GC #define DUMP_GC
#define DUMP_GC_FREE //#define DUMP_GC_FREE
#define DUMP_LEAKS 1 #define DUMP_LEAKS 1
#define DUMP_OBJECTS //#define DUMP_OBJECTS
#define DUMP_CLOSURE #define DUMP_CLOSURE
#define DUMP_OBJECTS //#define DUMP_OBJECTS
#define DUMP_ATOMS //#define DUMP_ATOMS
#define DUMP_SHAPES //#define DUMP_SHAPES
#define DUMP_MODULE_RESOLVE //#define DUMP_MODULE_RESOLVE
#define DUMP_PROMISE //#define DUMP_PROMISE
#endif #endif
/* test the GC by forcing it before each object allocation */ /* test the GC by forcing it before each object allocation */

View file

@ -85,6 +85,7 @@ void seghandle()
} }
void c_clean() { void c_clean() {
JS_FreeValue(js, c_process_fn);
cleanup(); cleanup();
gif_rec_end("out.gif"); gif_rec_end("out.gif");
saudio_shutdown(); saudio_shutdown();