Skip to content

Commit

Permalink
Make debug message callback Send + Sync.
Browse files Browse the repository at this point in the history
The debug callback function was not required to be Send+Sync.
This caused the native `Context` struct to become !Send + !Sync, which
is problematic because an OpenGL context can be passed to another
thread.
  • Loading branch information
surban authored and grovesNL committed Nov 27, 2023
1 parent 29ff917 commit edfd08e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub type Renderbuffer = <Context as HasContext>::Renderbuffer;
pub type Query = <Context as HasContext>::Query;
pub type UniformLocation = <Context as HasContext>::UniformLocation;
pub type TransformFeedback = <Context as HasContext>::TransformFeedback;
pub type DebugCallback = Box<dyn FnMut(u32, u32, u32, u32, &str)>;
pub type DebugCallback = Box<dyn FnMut(u32, u32, u32, u32, &str) + Send + Sync>;

pub struct ActiveUniform {
pub size: i32,
Expand Down Expand Up @@ -1191,7 +1191,7 @@ pub trait HasContext {

unsafe fn debug_message_callback<F>(&mut self, callback: F)
where
F: FnMut(u32, u32, u32, u32, &str) + 'static;
F: FnMut(u32, u32, u32, u32, &str) + Send + Sync + 'static;

unsafe fn get_debug_message_log(&self, count: u32) -> Vec<DebugMessageLogEntry>;

Expand Down
5 changes: 4 additions & 1 deletion src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ struct DebugCallbackRawPtr {
callback: *mut std::os::raw::c_void,
}

unsafe impl Send for DebugCallbackRawPtr {}
unsafe impl Sync for DebugCallbackRawPtr {}

impl Drop for DebugCallbackRawPtr {
fn drop(&mut self) {
unsafe {
Expand Down Expand Up @@ -2707,7 +2710,7 @@ impl HasContext for Context {

unsafe fn debug_message_callback<F>(&mut self, callback: F)
where
F: FnMut(u32, u32, u32, u32, &str) + 'static,
F: FnMut(u32, u32, u32, u32, &str) + Send + Sync + 'static,
{
match self.debug_callback {
Some(_) => {
Expand Down

0 comments on commit edfd08e

Please sign in to comment.