From 606dfbea93ea4968488c9c3b2410c847a6bdcd78 Mon Sep 17 00:00:00 2001 From: John Alanbrook Date: Fri, 22 Dec 2023 13:14:44 +0000 Subject: [PATCH] bug fixing --- quickjs/quickjs.c | 8 ++++++++ scripts/editor.js | 1 - scripts/entity.js | 2 -- scripts/std.js | 9 ++++++--- source/engine/debug/log.c | 7 ++++--- source/engine/font.c | 6 +++--- source/engine/font.h | 2 +- source/engine/input.c | 7 ++++--- source/engine/jsffi.c | 2 +- source/engine/resources.c | 2 +- source/engine/script.c | 8 -------- source/engine/script.h | 1 - source/engine/sound/smbPitchShift.h | 1 - .../engine/thirdparty/stb/include/stb_image_write.h | 2 +- source/engine/yugine.c | 12 +++++++++++- 15 files changed, 40 insertions(+), 30 deletions(-) diff --git a/quickjs/quickjs.c b/quickjs/quickjs.c index 5662aae..03d44da 100644 --- a/quickjs/quickjs.c +++ b/quickjs/quickjs.c @@ -16202,6 +16202,14 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, int argc, JSValue *argv, int flags) { JSRuntime *rt = caller_ctx->rt; +/* + JSValue nnjs = JS_GetPropertyStr(caller_ctx, func_obj, "name"); + const char *nnn = JS_ToCString(caller_ctx, nnjs); + printf("fn %s", nnn); + js_free(&rt->malloc_state, nnn); + JS_FreeValue(caller_ctx, nnjs); +*/ + JSContext *ctx; JSObject *p; JSFunctionBytecode *b; diff --git a/scripts/editor.js b/scripts/editor.js index 9040a9a..8fbbc52 100644 --- a/scripts/editor.js +++ b/scripts/editor.js @@ -1515,7 +1515,6 @@ var replpanel = Object.copy(inputpanel, { this.win.selectable = true; var log = cmd(84); log = log.slice(-5000); - return [ Mum.text({str:log, anchor:[0,0], offset:[0,-300].sub(this.scrolloffset), selectable: true}), Mum.text({str:this.value,color:Color.green, offset:[0,-290], caret: this.caret}) diff --git a/scripts/entity.js b/scripts/entity.js index 8966a32..b87be21 100644 --- a/scripts/entity.js +++ b/scripts/entity.js @@ -100,7 +100,6 @@ var gameobject = { clear() { for (var k in this.objects) { - Log.info(`Killing ${k}`); this.objects[k].kill(); }; this.objects = {}; @@ -519,7 +518,6 @@ var gameobject = { for (var key in this.components) { Register.unregister_obj(this.components[key]); - (`Destroying component ${key}`); this.components[key].kill(); this.components[key].gameobject = undefined; delete this.components[key]; diff --git a/scripts/std.js b/scripts/std.js index 911292a..9ae50ec 100644 --- a/scripts/std.js +++ b/scripts/std.js @@ -80,12 +80,15 @@ var Log = { }, stack(skip = 0) { - var stack = (new Error()).stack; + var err = new Error(); + var stack = err.stack; var n = stack.next('\n',0)+1; for (var i = 0; i < skip; i++) n = stack.next('\n', n)+1; - - this.write(stack.slice(n)); + Log.write(err.name); + Log.write(err.message); + Log.write(err.stack); +// Log.write(stack); }, clear() { diff --git a/source/engine/debug/log.c b/source/engine/debug/log.c index 2dd3f3e..49716f8 100644 --- a/source/engine/debug/log.c +++ b/source/engine/debug/log.c @@ -28,13 +28,14 @@ FILE *logfile = NULL; #define ERROR_BUFFER 1024 #define CONSOLE_BUF 1024*1024 /* 5MB */ -char *consolelog; +char *consolelog = NULL; static FILE *sout; void log_init() { consolelog = malloc(CONSOLE_BUF+1); + consolelog[0] = '\0'; sout = fdopen(dup(1),"w"); sout = stdout; } @@ -55,12 +56,12 @@ void mYughLog(int category, int priority, int line, const char *file, const char int len = vsnprintf(NULL, 0, message, args)+1; char *msg = malloc(len); va_end(args); - vsprintf(msg, message, arg2); + vsnprintf(msg, len, message, arg2); va_end(arg2); len = snprintf(NULL, 0, logfmt, file,line,logstr[priority], catstr[category], msg)+1; char *buffer = malloc(len); - sprintf(buffer, logfmt, file, line, logstr[priority], catstr[category], msg); + snprintf(buffer, len, logfmt, file, line, logstr[priority], catstr[category], msg); fprintf(stderr, "%s", buffer); fflush(stderr); diff --git a/source/engine/font.c b/source/engine/font.c index 794742e..1d81613 100644 --- a/source/engine/font.c +++ b/source/engine/font.c @@ -3,6 +3,7 @@ #include "log.h" #include "render.h" #include +#include "log.h" #include #include #include @@ -282,9 +283,8 @@ struct boundingbox text_bb(const char *text, float scale, float lw, float tracki { struct rgba dummy; HMM_Vec2 cursor = {0,0}; - const char *c = text; - const char *line, *wordstart, *drawstart; - line = drawstart = text; + const char *line, *wordstart; + line = text; while (*line != '\0') { if (isblank(*line)) { diff --git a/source/engine/font.h b/source/engine/font.h index 6a7ded4..3fb2291 100644 --- a/source/engine/font.h +++ b/source/engine/font.h @@ -25,7 +25,7 @@ struct sFont { int descent; int linegap; float emscale; - struct Character Characters[255]; + struct Character Characters[256]; sg_image texID; }; diff --git a/source/engine/input.c b/source/engine/input.c index b022709..4b072d4 100644 --- a/source/engine/input.c +++ b/source/engine/input.c @@ -223,19 +223,20 @@ void input_init() { mouse_states[i] = INPUT_UP; } -char keybuf[50]; +#define KEYBUFLEN 50 +char keybuf[KEYBUFLEN]; const char *keyname_extd(int key) { if (key > 289 && key < 302) { int num = key - 289; - sprintf(keybuf, "f%d", num); + snprintf(keybuf, KEYBUFLEN, "f%d", num); return keybuf; } if (key >= 320 && key <= 329) { int num = key - 320; - sprintf(keybuf, "kp%d", num); + snprintf(keybuf, KEYBUFLEN, "kp%d", num); return keybuf; } diff --git a/source/engine/jsffi.c b/source/engine/jsffi.c index 7304fb9..5c1c7a5 100644 --- a/source/engine/jsffi.c +++ b/source/engine/jsffi.c @@ -866,7 +866,7 @@ JSValue duk_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) break; case 84: - ret = JS_NewString(js, consolelog); + ret = consolelog ? JS_NewString(js, consolelog) : JS_NewString(js,""); break; case 85: diff --git a/source/engine/resources.c b/source/engine/resources.c index 325c99b..127e32d 100644 --- a/source/engine/resources.c +++ b/source/engine/resources.c @@ -167,7 +167,7 @@ char *str_replace_ext(const char *s, const char *newext) { FILE *path_open(const char *tag, const char *fmt, ...) { va_list args; va_start(args, fmt); - vsprintf(pathbuf, fmt, args); + vsnprintf(pathbuf, MAXPATH+1, fmt, args); va_end(args); FILE *f = fopen(pathbuf, tag); diff --git a/source/engine/script.c b/source/engine/script.c index fadf16c..6dd1be5 100644 --- a/source/engine/script.c +++ b/source/engine/script.c @@ -302,14 +302,6 @@ void script_callee(struct callee c, int argc, JSValue *argv) { js_callee_exec(&c, argc, argv); } -struct callee make_callee(JSValue fn, JSValue obj) -{ - struct callee c; - c.fn = JS_DupValue(js, fn); - c.obj = JS_DupValue(js, obj); - return c; -} - void free_callee(struct callee c) { JS_FreeValue(js,c.fn); diff --git a/source/engine/script.h b/source/engine/script.h index 87ddad4..c40deb2 100644 --- a/source/engine/script.h +++ b/source/engine/script.h @@ -32,7 +32,6 @@ time_t jso_file(const char *file); JSValue script_runfile(const char *file); void script_update(double dt); void script_draw(); -struct callee make_callee(JSValue fn, JSValue obj); void free_callee(struct callee c); void duk_run_err(); diff --git a/source/engine/sound/smbPitchShift.h b/source/engine/sound/smbPitchShift.h index da6a86a..3ea4793 100644 --- a/source/engine/sound/smbPitchShift.h +++ b/source/engine/sound/smbPitchShift.h @@ -40,7 +40,6 @@ #include #include -#define M_PI 3.14159265358979323846 #define MAX_FRAME_LENGTH 8192 #define false 0 #define true 1 diff --git a/source/engine/thirdparty/stb/include/stb_image_write.h b/source/engine/thirdparty/stb/include/stb_image_write.h index e4b32ed..de7ea9d 100755 --- a/source/engine/thirdparty/stb/include/stb_image_write.h +++ b/source/engine/thirdparty/stb/include/stb_image_write.h @@ -773,7 +773,7 @@ static int stbi_write_hdr_core(stbi__write_context *s, int x, int y, int comp, f #ifdef __STDC_LIB_EXT1__ len = sprintf_s(buffer, sizeof(buffer), "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x); #else - len = sprintf(buffer, "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x); + len = snprintf(buffer, 128, "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x); #endif s->func(s->context, buffer, len); diff --git a/source/engine/yugine.c b/source/engine/yugine.c index b8ad2d1..1ba80ae 100644 --- a/source/engine/yugine.c +++ b/source/engine/yugine.c @@ -86,7 +86,11 @@ const char *engine_info() { return ENGINEINFO; } static int argc; static char **args; -struct datastream *bjork; +void seghandle() +{ + js_stacktrace(); + exit(1); +} void c_init() { @@ -272,6 +276,12 @@ int main(int argc, char **argv) { snprintf(fname, 100, "yugine-%ld.log", now); log_setfile(fname); } +/* + signal(SIGSEGV, seghandle); + signal(SIGABRT, seghandle); + signal(SIGFPE, seghandle); + signal(SIGBUS, seghandle); +*/ #endif #ifdef STEAM