bug fixing

This commit is contained in:
John Alanbrook 2023-12-22 13:14:44 +00:00
parent 2ae45a5bb8
commit 606dfbea93
15 changed files with 40 additions and 30 deletions

View file

@ -16202,6 +16202,14 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj,
int argc, JSValue *argv, int flags) int argc, JSValue *argv, int flags)
{ {
JSRuntime *rt = caller_ctx->rt; 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; JSContext *ctx;
JSObject *p; JSObject *p;
JSFunctionBytecode *b; JSFunctionBytecode *b;

View file

@ -1515,7 +1515,6 @@ var replpanel = Object.copy(inputpanel, {
this.win.selectable = true; this.win.selectable = true;
var log = cmd(84); var log = cmd(84);
log = log.slice(-5000); log = log.slice(-5000);
return [ return [
Mum.text({str:log, anchor:[0,0], offset:[0,-300].sub(this.scrolloffset), selectable: true}), 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}) Mum.text({str:this.value,color:Color.green, offset:[0,-290], caret: this.caret})

View file

@ -100,7 +100,6 @@ var gameobject = {
clear() { clear() {
for (var k in this.objects) { for (var k in this.objects) {
Log.info(`Killing ${k}`);
this.objects[k].kill(); this.objects[k].kill();
}; };
this.objects = {}; this.objects = {};
@ -519,7 +518,6 @@ var gameobject = {
for (var key in this.components) { for (var key in this.components) {
Register.unregister_obj(this.components[key]); Register.unregister_obj(this.components[key]);
(`Destroying component ${key}`);
this.components[key].kill(); this.components[key].kill();
this.components[key].gameobject = undefined; this.components[key].gameobject = undefined;
delete this.components[key]; delete this.components[key];

View file

@ -80,12 +80,15 @@ var Log = {
}, },
stack(skip = 0) { stack(skip = 0) {
var stack = (new Error()).stack; var err = new Error();
var stack = err.stack;
var n = stack.next('\n',0)+1; var n = stack.next('\n',0)+1;
for (var i = 0; i < skip; i++) for (var i = 0; i < skip; i++)
n = stack.next('\n', n)+1; n = stack.next('\n', n)+1;
Log.write(err.name);
this.write(stack.slice(n)); Log.write(err.message);
Log.write(err.stack);
// Log.write(stack);
}, },
clear() { clear() {

View file

@ -28,13 +28,14 @@ FILE *logfile = NULL;
#define ERROR_BUFFER 1024 #define ERROR_BUFFER 1024
#define CONSOLE_BUF 1024*1024 /* 5MB */ #define CONSOLE_BUF 1024*1024 /* 5MB */
char *consolelog; char *consolelog = NULL;
static FILE *sout; static FILE *sout;
void log_init() void log_init()
{ {
consolelog = malloc(CONSOLE_BUF+1); consolelog = malloc(CONSOLE_BUF+1);
consolelog[0] = '\0';
sout = fdopen(dup(1),"w"); sout = fdopen(dup(1),"w");
sout = stdout; 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; int len = vsnprintf(NULL, 0, message, args)+1;
char *msg = malloc(len); char *msg = malloc(len);
va_end(args); va_end(args);
vsprintf(msg, message, arg2); vsnprintf(msg, len, message, arg2);
va_end(arg2); va_end(arg2);
len = snprintf(NULL, 0, logfmt, file,line,logstr[priority], catstr[category], msg)+1; len = snprintf(NULL, 0, logfmt, file,line,logstr[priority], catstr[category], msg)+1;
char *buffer = malloc(len); 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); fprintf(stderr, "%s", buffer);
fflush(stderr); fflush(stderr);

View file

@ -3,6 +3,7 @@
#include "log.h" #include "log.h"
#include "render.h" #include "render.h"
#include <ctype.h> #include <ctype.h>
#include "log.h"
#include <limits.h> #include <limits.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -282,9 +283,8 @@ struct boundingbox text_bb(const char *text, float scale, float lw, float tracki
{ {
struct rgba dummy; struct rgba dummy;
HMM_Vec2 cursor = {0,0}; HMM_Vec2 cursor = {0,0};
const char *c = text; const char *line, *wordstart;
const char *line, *wordstart, *drawstart; line = text;
line = drawstart = text;
while (*line != '\0') { while (*line != '\0') {
if (isblank(*line)) { if (isblank(*line)) {

View file

@ -25,7 +25,7 @@ struct sFont {
int descent; int descent;
int linegap; int linegap;
float emscale; float emscale;
struct Character Characters[255]; struct Character Characters[256];
sg_image texID; sg_image texID;
}; };

View file

@ -223,19 +223,20 @@ void input_init() {
mouse_states[i] = INPUT_UP; mouse_states[i] = INPUT_UP;
} }
char keybuf[50]; #define KEYBUFLEN 50
char keybuf[KEYBUFLEN];
const char *keyname_extd(int key) { const char *keyname_extd(int key) {
if (key > 289 && key < 302) { if (key > 289 && key < 302) {
int num = key - 289; int num = key - 289;
sprintf(keybuf, "f%d", num); snprintf(keybuf, KEYBUFLEN, "f%d", num);
return keybuf; return keybuf;
} }
if (key >= 320 && key <= 329) { if (key >= 320 && key <= 329) {
int num = key - 320; int num = key - 320;
sprintf(keybuf, "kp%d", num); snprintf(keybuf, KEYBUFLEN, "kp%d", num);
return keybuf; return keybuf;
} }

View file

@ -866,7 +866,7 @@ JSValue duk_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
break; break;
case 84: case 84:
ret = JS_NewString(js, consolelog); ret = consolelog ? JS_NewString(js, consolelog) : JS_NewString(js,"");
break; break;
case 85: case 85:

View file

@ -167,7 +167,7 @@ char *str_replace_ext(const char *s, const char *newext) {
FILE *path_open(const char *tag, const char *fmt, ...) { FILE *path_open(const char *tag, const char *fmt, ...) {
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
vsprintf(pathbuf, fmt, args); vsnprintf(pathbuf, MAXPATH+1, fmt, args);
va_end(args); va_end(args);
FILE *f = fopen(pathbuf, tag); FILE *f = fopen(pathbuf, tag);

View file

@ -302,14 +302,6 @@ void script_callee(struct callee c, int argc, JSValue *argv) {
js_callee_exec(&c, argc, 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) void free_callee(struct callee c)
{ {
JS_FreeValue(js,c.fn); JS_FreeValue(js,c.fn);

View file

@ -32,7 +32,6 @@ time_t jso_file(const char *file);
JSValue script_runfile(const char *file); JSValue script_runfile(const char *file);
void script_update(double dt); void script_update(double dt);
void script_draw(); void script_draw();
struct callee make_callee(JSValue fn, JSValue obj);
void free_callee(struct callee c); void free_callee(struct callee c);
void duk_run_err(); void duk_run_err();

View file

@ -40,7 +40,6 @@
#include <math.h> #include <math.h>
#include <stdio.h> #include <stdio.h>
#define M_PI 3.14159265358979323846
#define MAX_FRAME_LENGTH 8192 #define MAX_FRAME_LENGTH 8192
#define false 0 #define false 0
#define true 1 #define true 1

View file

@ -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__ #ifdef __STDC_LIB_EXT1__
len = sprintf_s(buffer, sizeof(buffer), "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x); len = sprintf_s(buffer, sizeof(buffer), "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x);
#else #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 #endif
s->func(s->context, buffer, len); s->func(s->context, buffer, len);

View file

@ -86,7 +86,11 @@ const char *engine_info() { return ENGINEINFO; }
static int argc; static int argc;
static char **args; static char **args;
struct datastream *bjork; void seghandle()
{
js_stacktrace();
exit(1);
}
void c_init() { void c_init() {
@ -272,6 +276,12 @@ int main(int argc, char **argv) {
snprintf(fname, 100, "yugine-%ld.log", now); snprintf(fname, 100, "yugine-%ld.log", now);
log_setfile(fname); log_setfile(fname);
} }
/*
signal(SIGSEGV, seghandle);
signal(SIGABRT, seghandle);
signal(SIGFPE, seghandle);
signal(SIGBUS, seghandle);
*/
#endif #endif
#ifdef STEAM #ifdef STEAM