Skip to content

Commit

Permalink
Fix crash on eframe wgpu when rendering a sync viewport in a sync vie…
Browse files Browse the repository at this point in the history
…wport

Better names
  • Loading branch information
konkitoman committed Nov 2, 2023
1 parent 46febb4 commit 75e6d3c
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions crates/eframe/src/native/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2177,7 +2177,7 @@ mod wgpu_integration {
viewport_builder,
pair,
render,
&mut viewports.borrow_mut(),
&viewports,
&builders,
beginning,
&painter,
Expand Down Expand Up @@ -2209,14 +2209,14 @@ mod wgpu_integration {
mut viewport_builder: ViewportBuilder,
pair: ViewportIdPair,
render: Box<dyn FnOnce(&egui::Context) + '_>,
viewports: &mut Viewports,
viewports: &RefCell<Viewports>,
builders: &RefCell<HashMap<ViewportId, ViewportBuilder>>,
time: Instant,
painter: &RefCell<egui_wgpu::winit::Painter>,
viewport_maps: &RefCell<HashMap<winit::window::WindowId, ViewportId>>,
) {
// Creating a new native window if is needed
if viewports.get(&pair).is_none() {
if viewports.borrow().get(&pair).is_none() {
let mut builders = builders.borrow_mut();

{
Expand All @@ -2226,6 +2226,8 @@ mod wgpu_integration {
}
}

let mut viewports = viewports.borrow_mut();

let Viewport { window, state, .. } =
viewports.entry(pair.this).or_insert(Viewport {
window: None,
Expand Down Expand Up @@ -2259,12 +2261,12 @@ mod wgpu_integration {

// render sync viewport

let window = viewports.get(&pair).cloned();
let Some(window) = window else { return };
let viewport = viewports.borrow().get(&pair).cloned();
let Some(viewport) = viewport else { return };
let output;
let Some(winit_state) = &mut *window.state.borrow_mut() else { return };
let Some(win) = window.window else { return };
let win = win.borrow();
let Some(winit_state) = &mut *viewport.state.borrow_mut() else { return };
let Some(window) = viewport.window else { return };
let win = window.borrow();
let mut input = winit_state.take_egui_input(&win);
input.time = Some(time.elapsed().as_secs_f64());
output = egui_ctx.run(input, pair, |ctx| {
Expand Down

0 comments on commit 75e6d3c

Please sign in to comment.