box the progress callback closure - fixes #134

This commit is contained in:
Roman Steiner 2025-02-25 10:50:32 +01:00
parent a5d279c31b
commit 807bc242e9
No known key found for this signature in database
GPG key ID: 2D3EE6D67E86519E

View file

@ -575,11 +575,13 @@ impl<'a, 'b> FullParams<'a, 'b> {
} }
match closure.into() { match closure.into() {
Some(mut closure) => { Some(closure) => {
self.fp.progress_callback = Some(trampoline::<F>); self.fp.progress_callback = Some(trampoline::<Box<dyn FnMut(i32)>>);
self.fp.progress_callback_user_data = &mut closure as *mut F as *mut c_void; let boxed_closure = Box::new(closure) as Box<dyn FnMut(i32)>;
// store the closure internally to make sure that the pointer above remains valid let boxed_closure = Box::new(boxed_closure);
self.progess_callback_safe = Some(Arc::new(Box::new(closure))); let raw_ptr = Box::into_raw(boxed_closure);
self.fp.progress_callback_user_data = raw_ptr as *mut c_void;
self.progess_callback_safe = None;
} }
None => { None => {
self.fp.progress_callback = None; self.fp.progress_callback = None;