fix gc error

This commit is contained in:
2026-02-21 03:07:38 -06:00
parent 5975298ec4
commit 6bdd375dbb
10 changed files with 259 additions and 131 deletions

123
surface.c
View File

@@ -92,10 +92,14 @@ QJSCLASS(SDL_Surface,)
JSValue make_surface(JSContext *js, SDL_Surface *s){
JS_FRAME(js);
JS_LOCAL(ret, SDL_Surface2js(js,s));
JS_SetPropertyStr(js, ret, "width", JS_NewInt32(js, s->w));
JS_SetPropertyStr(js, ret, "height", JS_NewInt32(js, s->h));
JS_SetPropertyStr(js, ret, "format", pixelformat2js(js, s->format));
JS_SetPropertyStr(js, ret, "pitch", JS_NewFloat64(js, s->pitch));
JSValue _w = JS_NewInt32(js, s->w);
JS_SetPropertyStr(js, ret, "width", _w);
JSValue _h = JS_NewInt32(js, s->h);
JS_SetPropertyStr(js, ret, "height", _h);
JSValue _fmt = pixelformat2js(js, s->format);
JS_SetPropertyStr(js, ret, "format", _fmt);
JSValue _pitch = JS_NewFloat64(js, s->pitch);
JS_SetPropertyStr(js, ret, "pitch", _pitch);
JS_RETURN(JS_Stone(js, ret));
}
@@ -232,10 +236,14 @@ JSC_CCALL(surface_toJSON,
JS_FRAME(js);
JS_LOCAL(obj, JS_NewObject(js));
JS_SetPropertyStr(js, obj, "width", JS_NewInt32(js, surf->w));
JS_SetPropertyStr(js, obj, "height", JS_NewInt32(js, surf->h));
JS_SetPropertyStr(js, obj, "format", pixelformat2js(js, surf->format));
JS_SetPropertyStr(js, obj, "pitch", JS_NewInt32(js, surf->pitch));
JSValue _w = JS_NewInt32(js, surf->w);
JS_SetPropertyStr(js, obj, "width", _w);
JSValue _h = JS_NewInt32(js, surf->h);
JS_SetPropertyStr(js, obj, "height", _h);
JSValue _fmt = pixelformat2js(js, surf->format);
JS_SetPropertyStr(js, obj, "format", _fmt);
JSValue _pitch = JS_NewInt32(js, surf->pitch);
JS_SetPropertyStr(js, obj, "pitch", _pitch);
int locked = 0;
if (SDL_MUSTLOCK(surf)) {
@@ -246,7 +254,8 @@ JSC_CCALL(surface_toJSON,
}
size_t byte_size = surf->pitch * surf->h;
JS_SetPropertyStr(js, obj, "pixels", js_new_blob_stoned_copy(js, surf->pixels, byte_size));
JSValue _pixels = js_new_blob_stoned_copy(js, surf->pixels, byte_size);
JS_SetPropertyStr(js, obj, "pixels", _pixels);
if (locked)
SDL_UnlockSurface(surf);
@@ -413,12 +422,17 @@ static JSValue compress_bc_common(JSContext *js, JSValueConst *argv, int argc, i
// Create result object
JS_FRAME(js);
JS_LOCAL(result, JS_NewObject(js));
JS_SetPropertyStr(js, result, "width", JS_NewInt32(js, width));
JS_SetPropertyStr(js, result, "height", JS_NewInt32(js, height));
JS_SetPropertyStr(js, result, "format", JS_NewString(js, format_name));
JS_SetPropertyStr(js, result, "pitch", JS_NewInt32(js, blocks_x * bytes_per_block));
JSValue _w = JS_NewInt32(js, width);
JS_SetPropertyStr(js, result, "width", _w);
JSValue _h = JS_NewInt32(js, height);
JS_SetPropertyStr(js, result, "height", _h);
JSValue _fmt = JS_NewString(js, format_name);
JS_SetPropertyStr(js, result, "format", _fmt);
JSValue _pitch = JS_NewInt32(js, blocks_x * bytes_per_block);
JS_SetPropertyStr(js, result, "pitch", _pitch);
JS_SetPropertyStr(js, result, "pixels", js_new_blob_stoned_copy(js, output, output_size));
JSValue _pixels = js_new_blob_stoned_copy(js, output, output_size);
JS_SetPropertyStr(js, result, "pixels", _pixels);
free(output);
JS_RETURN(result);
@@ -582,12 +596,17 @@ static JSValue compress_bc_channels(JSContext *js, JSValueConst *argv, int argc,
// Create result object
JS_FRAME(js);
JS_LOCAL(result, JS_NewObject(js));
JS_SetPropertyStr(js, result, "width", JS_NewInt32(js, width));
JS_SetPropertyStr(js, result, "height", JS_NewInt32(js, height));
JS_SetPropertyStr(js, result, "format", JS_NewString(js, format_name));
JS_SetPropertyStr(js, result, "pitch", JS_NewInt32(js, blocks_x * bytes_per_block));
JSValue _w = JS_NewInt32(js, width);
JS_SetPropertyStr(js, result, "width", _w);
JSValue _h = JS_NewInt32(js, height);
JS_SetPropertyStr(js, result, "height", _h);
JSValue _fmt = JS_NewString(js, format_name);
JS_SetPropertyStr(js, result, "format", _fmt);
JSValue _pitch = JS_NewInt32(js, blocks_x * bytes_per_block);
JS_SetPropertyStr(js, result, "pitch", _pitch);
JS_SetPropertyStr(js, result, "pixels", js_new_blob_stoned_copy(js, output, output_size));
JSValue _pixels = js_new_blob_stoned_copy(js, output, output_size);
JS_SetPropertyStr(js, result, "pixels", _pixels);
free(output);
JS_RETURN(result);
@@ -769,10 +788,14 @@ static JSValue surface_to_image(JSContext *js, SDL_Surface *surf)
JS_FRAME(js);
JS_LOCAL(obj, JS_NewObject(js));
JS_SetPropertyStr(js, obj, "width", JS_NewInt32(js, surf->w));
JS_SetPropertyStr(js, obj, "height", JS_NewInt32(js, surf->h));
JS_SetPropertyStr(js, obj, "format", pixelformat2js(js, surf->format));
JS_SetPropertyStr(js, obj, "pitch", JS_NewInt32(js, surf->pitch));
JSValue _w = JS_NewInt32(js, surf->w);
JS_SetPropertyStr(js, obj, "width", _w);
JSValue _h = JS_NewInt32(js, surf->h);
JS_SetPropertyStr(js, obj, "height", _h);
JSValue _fmt = pixelformat2js(js, surf->format);
JS_SetPropertyStr(js, obj, "format", _fmt);
JSValue _pitch = JS_NewInt32(js, surf->pitch);
JS_SetPropertyStr(js, obj, "pitch", _pitch);
int locked = 0;
if (SDL_MUSTLOCK(surf)) {
@@ -783,12 +806,14 @@ static JSValue surface_to_image(JSContext *js, SDL_Surface *surf)
}
size_t byte_size = surf->pitch * surf->h;
JS_SetPropertyStr(js, obj, "pixels", js_new_blob_stoned_copy(js, surf->pixels, byte_size));
JSValue _pixels = js_new_blob_stoned_copy(js, surf->pixels, byte_size);
JS_SetPropertyStr(js, obj, "pixels", _pixels);
if (locked)
SDL_UnlockSurface(surf);
JS_SetPropertyStr(js, obj, "depth", JS_NewInt32(js, SDL_BITSPERPIXEL(surf->format)));
JSValue _depth = JS_NewInt32(js, SDL_BITSPERPIXEL(surf->format));
JS_SetPropertyStr(js, obj, "depth", _depth);
JS_SetPropertyStr(js, obj, "hdr", JS_FALSE);
JS_RETURN(obj);
@@ -1056,15 +1081,21 @@ JSC_CCALL(surface_convert_generic,
// Create result image object
JS_FRAME(js);
JS_LOCAL(result, JS_NewObject(js));
JS_SetPropertyStr(js, result, "width", JS_NewInt32(js, src_width));
JS_SetPropertyStr(js, result, "height", JS_NewInt32(js, src_height));
JS_SetPropertyStr(js, result, "format", pixelformat2js(js, dst_format));
JS_SetPropertyStr(js, result, "pitch", JS_NewInt32(js, dst_pitch));
JSValue _w = JS_NewInt32(js, src_width);
JS_SetPropertyStr(js, result, "width", _w);
JSValue _h = JS_NewInt32(js, src_height);
JS_SetPropertyStr(js, result, "height", _h);
JSValue _fmt = pixelformat2js(js, dst_format);
JS_SetPropertyStr(js, result, "format", _fmt);
JSValue _pitch = JS_NewInt32(js, dst_pitch);
JS_SetPropertyStr(js, result, "pitch", _pitch);
JS_SetPropertyStr(js, result, "pixels", js_new_blob_stoned_copy(js, dst_pixels, dst_size));
JSValue _pixels = js_new_blob_stoned_copy(js, dst_pixels, dst_size);
JS_SetPropertyStr(js, result, "pixels", _pixels);
free(dst_pixels);
JS_SetPropertyStr(js, result, "depth", JS_NewInt32(js, SDL_BITSPERPIXEL(dst_format)));
JSValue _depth = JS_NewInt32(js, SDL_BITSPERPIXEL(dst_format));
JS_SetPropertyStr(js, result, "depth", _depth);
JS_SetPropertyStr(js, result, "hdr", JS_FALSE);
JS_RETURN(result);
@@ -1076,16 +1107,26 @@ CELL_USE_INIT(
JS_FRAME(js);
JS_LOCAL(ctor, JS_NewCFunction2(js, js_surface_constructor, "surface", 1, JS_CFUNC_generic, 0));
JS_SetPropertyStr(js, ctor, "convert", JS_NewCFunction(js, js_surface_convert_generic, "convert", 2));
JS_SetPropertyStr(js, ctor, "compress_bc1", JS_NewCFunction(js, js_surface_compress_bc1, "compress_bc1", 2));
JS_SetPropertyStr(js, ctor, "compress_bc3", JS_NewCFunction(js, js_surface_compress_bc3, "compress_bc3", 2));
JS_SetPropertyStr(js, ctor, "compress_bc4", JS_NewCFunction(js, js_surface_compress_bc4, "compress_bc4", 1));
JS_SetPropertyStr(js, ctor, "compress_bc5", JS_NewCFunction(js, js_surface_compress_bc5, "compress_bc5", 1));
JS_SetPropertyStr(js, ctor, "scale", JS_NewCFunction(js, js_surface_scale_img, "scale", 2));
JS_SetPropertyStr(js, ctor, "fill", JS_NewCFunction(js, js_surface_fill_img, "fill", 2));
JS_SetPropertyStr(js, ctor, "rect", JS_NewCFunction(js, js_surface_rect_img, "rect", 3));
JS_SetPropertyStr(js, ctor, "blit", JS_NewCFunction(js, js_surface_blit_img, "blit", 5));
JS_SetPropertyStr(js, ctor, "dup", JS_NewCFunction(js, js_surface_dup_img, "dup", 1));
JSValue _convert = JS_NewCFunction(js, js_surface_convert_generic, "convert", 2);
JS_SetPropertyStr(js, ctor, "convert", _convert);
JSValue _bc1 = JS_NewCFunction(js, js_surface_compress_bc1, "compress_bc1", 2);
JS_SetPropertyStr(js, ctor, "compress_bc1", _bc1);
JSValue _bc3 = JS_NewCFunction(js, js_surface_compress_bc3, "compress_bc3", 2);
JS_SetPropertyStr(js, ctor, "compress_bc3", _bc3);
JSValue _bc4 = JS_NewCFunction(js, js_surface_compress_bc4, "compress_bc4", 1);
JS_SetPropertyStr(js, ctor, "compress_bc4", _bc4);
JSValue _bc5 = JS_NewCFunction(js, js_surface_compress_bc5, "compress_bc5", 1);
JS_SetPropertyStr(js, ctor, "compress_bc5", _bc5);
JSValue _scale = JS_NewCFunction(js, js_surface_scale_img, "scale", 2);
JS_SetPropertyStr(js, ctor, "scale", _scale);
JSValue _fill = JS_NewCFunction(js, js_surface_fill_img, "fill", 2);
JS_SetPropertyStr(js, ctor, "fill", _fill);
JSValue _rect = JS_NewCFunction(js, js_surface_rect_img, "rect", 3);
JS_SetPropertyStr(js, ctor, "rect", _rect);
JSValue _blit = JS_NewCFunction(js, js_surface_blit_img, "blit", 5);
JS_SetPropertyStr(js, ctor, "blit", _blit);
JSValue _dup = JS_NewCFunction(js, js_surface_dup_img, "dup", 1);
JS_SetPropertyStr(js, ctor, "dup", _dup);
JS_RETURN(ctor);
)