Commite3a99b4eRecorded19 Sep 2026Repositorysigil-graphics
Treat a FAILED sokol image as a creation error, not only an invalid id
Message
sg_make_image returns a usable-looking id for an image whose creation failed (the web depth image was one); sg_update_image and passes on such an image are silent no-ops. Check the resource state at the four creation sites and release the slot on the error path.
Changed
src/c/graphics.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)Diff
src/c/graphics.cmodified
@@ -928,7 +928,8 @@ static Value native_load_texture(SigilVM *vm, int argc, Value *args)
928
}; 929
sg_image img = sg_make_image(&img_desc); 930
−931
if (img.id == SG_INVALID_ID) {+931
if (img.id == SG_INVALID_ID || sg_query_image_state(img) != SG_RESOURCESTATE_VALID) {+932
if (img.id != SG_INVALID_ID) sg_destroy_image(img); /* a FAILED slot still holds an id */ 933
sigil__vm_set_error(vm, SIGIL_ERR_RUNTIME, 934
"load-texture: failed to create GPU texture"); 935
return SIGIL_FALSE;@@ -1071,7 +1072,8 @@ static Value native_make_texture_from_pixels(SigilVM *vm, int argc, Value *args)
1072
.pixel_format = SG_PIXELFORMAT_RGBA8, 1073
}; 1074
sg_image img = sg_make_image(&img_desc);−1074
if (img.id == SG_INVALID_ID) {+1075
if (img.id == SG_INVALID_ID || sg_query_image_state(img) != SG_RESOURCESTATE_VALID) {+1076
if (img.id != SG_INVALID_ID) sg_destroy_image(img); /* a FAILED slot still holds an id */ 1077
sigil__vm_set_error(vm, SIGIL_ERR_RUNTIME, 1078
"make-texture-from-pixels: failed to create GPU texture"); 1079
return SIGIL_FALSE;@@ -1387,7 +1389,8 @@ static Value native_make_render_target(SigilVM *vm, int argc, Value *args)
1389
.height = h, 1390
}; 1391
sg_image img = sg_make_image(&img_desc);−1390
if (img.id == SG_INVALID_ID) {+1392
if (img.id == SG_INVALID_ID || sg_query_image_state(img) != SG_RESOURCESTATE_VALID) {+1393
if (img.id != SG_INVALID_ID) sg_destroy_image(img); /* a FAILED slot still holds an id */ 1394
sigil__vm_set_error(vm, SIGIL_ERR_RUNTIME, 1395
"make-render-target: failed to create color image"); 1396
return SIGIL_FALSE;@@ -1434,7 +1437,8 @@ static Value native_make_render_target(SigilVM *vm, int argc, Value *args)
1437
.height = h, 1438
}; 1439
depth_img = sg_make_image(&depth_desc);−1437
if (depth_img.id == SG_INVALID_ID) {+1440
if (depth_img.id == SG_INVALID_ID || sg_query_image_state(depth_img) != SG_RESOURCESTATE_VALID) {+1441
if (depth_img.id != SG_INVALID_ID) sg_destroy_image(depth_img); 1442
sg_destroy_view(tex_view); 1443
sg_destroy_view(att_view); 1444
sg_destroy_image(img);