From e23186db8e812a5032e59aa7aba778d3f4aa87d9 Mon Sep 17 00:00:00 2001 From: Kirill Chibisov Date: Mon, 26 Jun 2023 01:04:38 +0400 Subject: [PATCH] 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. --- examples/util/fill.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/examples/util/fill.rs b/examples/util/fill.rs index e08f9224..7f1f1b1f 100644 --- a/examples/util/fill.rs +++ b/examples/util/fill.rs @@ -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> = 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>> = ManuallyDrop::new(RefCell::new(None)); } GC.with(|gc| {