Skip to content

Commit

Permalink
stop unsoundly dropping CONTEXT in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrgani committed Dec 18, 2024
1 parent b4d0436 commit 4ed7206
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -466,8 +467,9 @@ impl Context {
}
}

// dropping `Context` is unsound (#693)
#[no_mangle]
static mut CONTEXT: Option<Context> = None;
static mut CONTEXT: Option<ManuallyDrop<Context>> = None;

// This is required for #[macroquad::test]
//
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 4ed7206

Please sign in to comment.