Disallow cleanup for TLS in examples

Fixes issue on Wayland due to drop order, since TLS is being dropped
after the event loop, while it shouldn't. In particular it fixes the
crash in the window_run_return example.
This commit is contained in:
Kirill Chibisov 2023-06-26 01:04:38 +04:00 committed by GitHub
parent 059abb06fc
commit e23186db8e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -14,6 +14,7 @@ pub(super) fn fill_window(window: &Window) {
use softbuffer::{Context, Surface};
use std::cell::RefCell;
use std::collections::HashMap;
use std::mem::ManuallyDrop;
use std::num::NonZeroU32;
use winit::window::WindowId;
@ -43,8 +44,12 @@ pub(super) fn fill_window(window: &Window) {
}
thread_local! {
/// A static, thread-local map of graphics contexts to open windows.
static GC: RefCell<Option<GraphicsContext>> = RefCell::new(None);
// NOTE: You should never do things like that, create context and drop it before
// you drop the event loop. We do this for brevity to not blow up examples. We use
// ManuallyDrop to prevent destructors from running.
//
// A static, thread-local map of graphics contexts to open windows.
static GC: ManuallyDrop<RefCell<Option<GraphicsContext>>> = ManuallyDrop::new(RefCell::new(None));
}
GC.with(|gc| {