diff --git a/src/lib.rs b/src/lib.rs index c9d5b131..1a986237 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -40,6 +40,7 @@ use miniquad::*; use std::collections::{HashMap, HashSet}; use std::future::Future; +use std::mem::ManuallyDrop; use std::panic::AssertUnwindSafe; use std::pin::Pin; @@ -466,8 +467,9 @@ impl Context { } } +// dropping `Context` is unsound (#693) #[no_mangle] -static mut CONTEXT: Option = None; +static mut CONTEXT: Option> = None; // This is required for #[macroquad::test] // @@ -878,7 +880,7 @@ impl Window { draw_call_vertex_capacity, draw_call_index_capacity, ); - unsafe { CONTEXT = Some(context) }; + unsafe { CONTEXT = Some(ManuallyDrop::new(context)) }; Box::new(Stage { main_future: Box::pin(future),