Acquire context reference after argument validation in image_handle_load

luaL_error can perform a long jump and never return. `drop` might not
get called on the AppDataRef, leaving it permanently borrowed.
This commit is contained in:
meehl committed 2026-08-27 15:31:03 +02:00
1 parent ac8cf3946e
commit 4e67aa72c0
1 file changed
+3 -3
+3 -3
View File
@@ -177,9 +177,6 @@ unsafe extern "C-unwind" fn image_handle_unload(state: *mut ffi::lua_State) -> c
unsafe extern "C-unwind" fn image_handle_load(state: *mut ffi::lua_State) -> c_int {
let handle = unsafe { get_image_handle(state, 1) };
let lua = unsafe { Lua::get_or_init_from_ptr(state) };
let ctx = lua.app_data_ref::<Context>().unwrap();
// Path
let path_ptr = unsafe { ffi::luaL_checklstring(state, 2, ptr::null_mut()) };
@@ -242,6 +239,9 @@ unsafe extern "C-unwind" fn image_handle_load(state: *mut ffi::lua_State) -> c_i
// Load / update
let handle = unsafe { &mut *handle };
let lua = unsafe { Lua::get_or_init_from_ptr(state) };
let ctx = lua.app_data_ref::<Context>().unwrap();
match &mut handle.texture {
Some(texture_handle) => {
// Keep the existing TextureHandle and update underlying texture