diff --git a/Makefile b/Makefile index 78474c1..2fb38d0 100755 --- a/Makefile +++ b/Makefile @@ -58,6 +58,7 @@ endif ifdef LEAK CPPFLAGS += -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer -DLEAK + INFO := $(INFO)_leak endif ifeq ($(OPT),small) diff --git a/scripts/engine.js b/scripts/engine.js index 2e7b616..4544e78 100644 --- a/scripts/engine.js +++ b/scripts/engine.js @@ -156,6 +156,7 @@ console.pprint = function(msg,lvl = 0) { var file = "nofile"; var line = 0; + console.rec(0,msg,file,line); var caller = (new Error()).stack.split('\n')[2]; if (caller) { @@ -453,12 +454,12 @@ prosperon.touchrelease = function(touches){}; prosperon.touchmove = function(touches){}; prosperon.clipboardpaste = function(str){}; prosperon.quit = function(){ - console.info(profile.printreport(profcache, "USE REPORT")); - console.info(profile.printreport(entityreport, "ENTITY REPORT")); + say(profile.printreport(profcache, "USE REPORT")); + say(profile.printreport(entityreport, "ENTITY REPORT")); console.info("QUITTING"); 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"); diff --git a/scripts/std.js b/scripts/std.js index f4ecba3..179ac45 100644 --- a/scripts/std.js +++ b/scripts/std.js @@ -248,7 +248,7 @@ Cmdline.register_order("play", function(argv) { console.info(`Starting game with window size ${window.size} and render ${window.rendersize}.`); game.engine_start(function() { - render.set_font("fonts/c64.ttf", 8); + render.set_font("fonts/c64.ttf", 8); global.app = actor.spawn("game.js"); if (project.icon) window.set_icon(game.texture(project.icon)); game.camera = world.spawn("scripts/camera2d"); diff --git a/source/engine/jsffi.c b/source/engine/jsffi.c index 22d3be2..3ad5d8d 100644 --- a/source/engine/jsffi.c +++ b/source/engine/jsffi.c @@ -101,14 +101,6 @@ JSValue js_getpropidx(JSValue v, uint32_t i) 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); } JSValue js_getpropstr(JSValue v, const char *str) { @@ -1549,7 +1541,6 @@ void ffi_load() { QJSGLOBALCLASS(dspsound); QJSGLOBALCLASS(pshape); QJSGLOBALCLASS(performance); - QJSGLOBALCLASS(circle2d); QJSGLOBALCLASS(poly2d); QJSGLOBALCLASS(edge2d); @@ -1560,7 +1551,7 @@ void ffi_load() { JS_SetPropertyStr(js, globalThis, "texture", JS_DupValue(js,texture_proto)); //JS_SetPropertyStr(js, globalThis, "steam", js_init_steam(js)); - + sound_proto = JS_NewObject(js); JS_SetPropertyStr(js,globalThis, "sound_proto", sound_proto); JS_SetPropertyFunctionList(js, sound_proto, js_sound_funcs, countof(js_sound_funcs)); @@ -1568,7 +1559,3 @@ void ffi_load() { JS_FreeValue(js,globalThis); } - -void ffi_stop() -{ -} \ No newline at end of file diff --git a/source/engine/jsffi.h b/source/engine/jsffi.h index 9642510..67d28b7 100644 --- a/source/engine/jsffi.h +++ b/source/engine/jsffi.h @@ -120,7 +120,6 @@ JS_SetClassProto(js, js_##TYPE##_id, TYPE##_proto); \ #define countof(x) (sizeof(x)/sizeof((x)[0])) void ffi_load(); -void ffi_stop(); JSValue vec22js(HMM_Vec2 v); HMM_Vec2 js2vec2(JSValue v); diff --git a/source/engine/script.c b/source/engine/script.c index 9eb4ad4..62b664c 100644 --- a/source/engine/script.c +++ b/source/engine/script.c @@ -24,7 +24,7 @@ void script_startup() { size_t len; char *eng = slurp_text("scripts/engine.js", &len); JSValue v = script_eval("scripts/engine.js", eng); - JS_FreeValue(js,v); + JS_FreeValue(js, v); free(eng); } static int stopped = 0; @@ -35,17 +35,19 @@ void script_stop() return; #endif printf("FREEING CONTEXT\n"); - ffi_stop(); - JS_FreeContext(js); + script_gc(); - JS_FreeRuntime(rt); + + JS_FreeContext(js); js = NULL; + JS_FreeRuntime(rt); rt = NULL; } void script_gc() { JS_RunGC(rt); } void js_stacktrace() { + if (!js) return; #ifndef NDEBUG script_evalf("console.stack();"); #endif @@ -53,13 +55,19 @@ void js_stacktrace() { void script_evalf(const char *format, ...) { - char fmtbuf[4096]; + JSValue obj; va_list args; va_start(args, format); - vsnprintf(fmtbuf, 4096, format, args); + int len = vsnprintf(NULL, 0, format, args); + va_end(args); + + char *eval = malloc(len+1); + va_start(args, format); + vsnprintf(eval, len+1, format, args); va_end(args); - JSValue obj = JS_Eval(js, fmtbuf, strlen(fmtbuf), "C eval", JS_EVAL_FLAGS); + obj = JS_Eval(js, eval, len, "C eval", JS_EVAL_FLAGS); + free(eval); js_print_exception(obj); JS_FreeValue(js,obj); } diff --git a/source/engine/thirdparty/quickjs/quickjs.c b/source/engine/thirdparty/quickjs/quickjs.c index d5284c1..9132a5c 100644 --- a/source/engine/thirdparty/quickjs/quickjs.c +++ b/source/engine/thirdparty/quickjs/quickjs.c @@ -114,17 +114,17 @@ void quickjs_set_dumpout(FILE *f) #ifdef DUMP //#define DUMP_FREE #define DUMP_MEM -#define DUMP_CLOSURE +//#define DUMP_CLOSURE #define DUMP_GC -#define DUMP_GC_FREE +//#define DUMP_GC_FREE #define DUMP_LEAKS 1 -#define DUMP_OBJECTS +//#define DUMP_OBJECTS #define DUMP_CLOSURE -#define DUMP_OBJECTS -#define DUMP_ATOMS -#define DUMP_SHAPES -#define DUMP_MODULE_RESOLVE -#define DUMP_PROMISE +//#define DUMP_OBJECTS +//#define DUMP_ATOMS +//#define DUMP_SHAPES +//#define DUMP_MODULE_RESOLVE +//#define DUMP_PROMISE #endif /* test the GC by forcing it before each object allocation */ diff --git a/source/engine/yugine.c b/source/engine/yugine.c index a6699e5..d7b2535 100644 --- a/source/engine/yugine.c +++ b/source/engine/yugine.c @@ -85,6 +85,7 @@ void seghandle() } void c_clean() { + JS_FreeValue(js, c_process_fn); cleanup(); gif_rec_end("out.gif"); saudio_shutdown();