diff --git a/src/pob/api/image_handle.rs b/src/pob/api/image_handle.rs index 5a4f8ac..f1046a9 100644 --- a/src/pob/api/image_handle.rs +++ b/src/pob/api/image_handle.rs @@ -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::().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::().unwrap(); + match &mut handle.texture { Some(texture_handle) => { // Keep the existing TextureHandle and update underlying texture