From 601e4b1fe4f44433aa819642cfed37a44d1254a2 Mon Sep 17 00:00:00 2001 From: Sebastian Urban Date: Mon, 8 Jul 2024 19:08:36 +0200 Subject: [PATCH] debug_message_callback: use Fn instead of FnMut The callback may be called simultaenously from different threads. Thus it must use a non-mutable function. --- src/lib.rs | 4 ++-- src/native.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index ac2d24f..240e4af 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -37,7 +37,7 @@ pub type Renderbuffer = ::Renderbuffer; pub type Query = ::Query; pub type UniformLocation = ::UniformLocation; pub type TransformFeedback = ::TransformFeedback; -pub type DebugCallback = Box; +pub type DebugCallback = Box; pub struct ActiveUniform { pub size: i32, @@ -1523,7 +1523,7 @@ pub trait HasContext: __private::Sealed { unsafe fn debug_message_callback(&mut self, callback: F) where - F: FnMut(u32, u32, u32, u32, &str) + Send + Sync + 'static; + F: Fn(u32, u32, u32, u32, &str) + Send + Sync + 'static; unsafe fn get_debug_message_log(&self, count: u32) -> Vec; diff --git a/src/native.rs b/src/native.rs index bb0046a..5db0445 100644 --- a/src/native.rs +++ b/src/native.rs @@ -3368,7 +3368,7 @@ impl HasContext for Context { unsafe fn debug_message_callback(&mut self, callback: F) where - F: FnMut(u32, u32, u32, u32, &str) + Send + Sync + 'static, + F: Fn(u32, u32, u32, u32, &str) + Send + Sync + 'static, { match self.debug_callback { Some(_) => { @@ -3889,7 +3889,7 @@ extern "system" fn raw_debug_message_callback( user_param: *mut std::ffi::c_void, ) { let _result = std::panic::catch_unwind(move || unsafe { - let callback: &mut DebugCallback = &mut *(user_param as *mut DebugCallback); + let callback: &DebugCallback = &*(user_param as *const DebugCallback); let slice = std::slice::from_raw_parts(message as *const u8, length as usize); let msg = String::from_utf8_lossy(slice); (callback)(source, gltype, id, severity, &msg);