Skip to content

Commit

Permalink
Remove the ManuallyDrop workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
notgull committed Jul 15, 2023
1 parent 0fd050e commit 5c246c2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
7 changes: 1 addition & 6 deletions examples/util/fill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ pub(super) fn fill_window(window: &(impl FullHandleTy + Clone)) {
use softbuffer::{Context, Surface};
use std::cell::RefCell;
use std::collections::HashMap;
use std::mem::ManuallyDrop;
use std::num::NonZeroU32;
use std::rc::Rc;
use winit::window::WindowId;
Expand Down Expand Up @@ -59,12 +58,8 @@ pub(super) fn fill_window(window: &(impl FullHandleTy + Clone)) {
}

thread_local! {
// 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));
static GC: RefCell<Option<GraphicsContext>> = RefCell::new(None);
}

GC.with(|gc| {
Expand Down
14 changes: 8 additions & 6 deletions examples/window_tabbing.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![allow(clippy::single_match)]

#[cfg(target_os = "macos")]
use std::{collections::HashMap, num::NonZeroUsize};
use std::{collections::HashMap, num::NonZeroUsize, rc::Rc};

#[cfg(target_os = "macos")]
use simple_logger::SimpleLogger;
Expand All @@ -24,7 +24,7 @@ fn main() {
let event_loop = EventLoop::new();

let mut windows = HashMap::new();
let window = Window::new(&event_loop).unwrap();
let window = Rc::new(Window::new(&event_loop).unwrap());
println!("Opened a new window: {:?}", window.id());
windows.insert(window.id(), window);

Expand Down Expand Up @@ -63,10 +63,12 @@ fn main() {
} => match logical_key.as_ref() {
Key::Character("t") => {
let tabbing_id = windows.get(&window_id).unwrap().tabbing_identifier();
let window = WindowBuilder::new()
.with_tabbing_identifier(&tabbing_id)
.build(event_loop)
.unwrap();
let window = Rc::new(
WindowBuilder::new()
.with_tabbing_identifier(&tabbing_id)
.build(event_loop)
.unwrap(),
);
println!("Added a new tab: {:?}", window.id());
windows.insert(window.id(), window);
}
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/orbital/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::str;

use crate::dpi::{PhysicalPosition, PhysicalSize};

pub use self::event_loop::{EventLoop, EventLoopProxy, EventLoopWindowTarget};
pub use self::event_loop::{EventLoop, EventLoopProxy, EventLoopWindowTarget, OwnedDisplayHandle};
mod event_loop;

pub use self::window::Window;
Expand Down

0 comments on commit 5c246c2

Please sign in to comment.