Skip to content

Commit

Permalink
More Id:s, less cloning
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Nov 11, 2023
1 parent 962eb02 commit 6866e58
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions crates/eframe/src/native/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -712,27 +712,33 @@ mod glow_integration {
fn on_resume(&mut self, event_loop: &EventLoopWindowTarget<UserEvent>) -> Result<()> {
crate::profile_function!();

let viewports = self
let viewports: Vec<ViewportId> = self
.viewports
.values()
.cloned()
.collect::<Vec<Rc<RefCell<Viewport>>>>();
for viewport in viewports {
if viewport.borrow().gl_surface.is_none() {
self.init_viewport(&viewport, event_loop)?;
}
.iter()
.filter(|(_, viewport)| viewport.borrow().gl_surface.is_none())
.map(|(id, _)| *id)
.collect();

for viewport_id in viewports {
self.init_viewport(viewport_id, event_loop)?;
}
Ok(())
}

#[allow(unsafe_code)]
pub(crate) fn init_viewport(
&mut self,
viewport: &Rc<RefCell<Viewport>>,
viewport_id: ViewportId,
event_loop: &EventLoopWindowTarget<UserEvent>,
) -> Result<()> {
crate::profile_function!();

let viewport = self
.viewports
.get(&viewport_id)
.cloned()
.expect("viewport doesn't exist");

let builder = &self.builders[&viewport.borrow().id_pair.this];
let mut viewport = viewport.borrow_mut();
// make sure we have a window or create one.
Expand Down Expand Up @@ -1160,8 +1166,6 @@ mod glow_integration {
.or_insert(viewport_builder);
}

let viewport = glutin.viewports[&id_pair.this].clone();

#[allow(unsafe_code)]
let event_loop = unsafe {
WINIT_EVENT_LOOP.with(|event_loop| {
Expand All @@ -1170,7 +1174,7 @@ mod glow_integration {
};

glutin
.init_viewport(&viewport, event_loop)
.init_viewport(id_pair.this, event_loop)
.expect("Cannot init window on egui::Context::show_viewport_immediate");
}

Expand Down

0 comments on commit 6866e58

Please sign in to comment.