Skip to content

Commit

Permalink
Fix crash when rendering a sync viewport in a sync viewport
Browse files Browse the repository at this point in the history
  • Loading branch information
konkitoman committed Nov 1, 2023
1 parent 72a7ee4 commit 2b8e5b5
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions crates/eframe/src/native/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1084,9 +1084,9 @@ mod glow_integration {
viewport_builder,
pair,
render,
&mut c_glutin.borrow_mut(),
&c_glutin,
&c_gl,
&mut c_painter.borrow_mut(),
&c_painter,
c_time,
);
},
Expand All @@ -1110,15 +1110,17 @@ mod glow_integration {
mut viewport_builder: ViewportBuilder,
pair: ViewportIdPair,
render: Box<dyn FnOnce(&egui::Context) + '_>,
glutin: &mut GlutinWindowContext,
glutin: &RefCell<GlutinWindowContext>,
gl: &glow::Context,
painter: &mut egui_glow::Painter,
painter: &RefCell<egui_glow::Painter>,
time: Instant,
) {
let has_window = glutin.viewports.get(&pair).is_some();
let has_window = glutin.borrow().viewports.get(&pair).is_some();

// This will create a new native window if is needed
if !has_window {
let mut glutin = glutin.borrow_mut();

// Inherit parent icon if none
{
if viewport_builder.icon.is_none() && glutin.builders.get(&pair).is_none() {
Expand Down Expand Up @@ -1158,7 +1160,7 @@ mod glow_integration {

// Rendering the sync viewport

let window = glutin.viewports.get(&pair).cloned();
let window = glutin.borrow().viewports.get(&pair).cloned();
let Some(window) = window else { return };
let output;

Expand All @@ -1176,6 +1178,9 @@ mod glow_integration {

let clipped_primitives = egui_ctx.tessellate(output.shapes, pair.this);

let mut glutin = glutin.borrow_mut();
let mut painter = painter.borrow_mut();

glutin.current_gl_context = Some(
glutin
.current_gl_context
Expand Down Expand Up @@ -2139,10 +2144,10 @@ mod wgpu_integration {
pair,
render,
&c_viewports,
&mut c_builders.borrow_mut(),
&c_builders,
c_time,
&mut c_painter.borrow_mut(),
&mut c_windows_id.borrow_mut(),
&c_painter,
&c_windows_id,
);
},
);
Expand All @@ -2167,13 +2172,14 @@ mod wgpu_integration {
pair: ViewportIdPair,
render: Box<dyn FnOnce(&egui::Context) + '_>,
c_viewports: &Viewports,
builders: &mut HashMap<ViewportId, ViewportBuilder>,
builders: &RefCell<HashMap<ViewportId, ViewportBuilder>>,
c_time: Instant,
c_painter: &mut egui_wgpu::winit::Painter,
c_windows_id: &mut HashMap<winit::window::WindowId, ViewportId>,
c_painter: &RefCell<egui_wgpu::winit::Painter>,
c_windows_id: &RefCell<HashMap<winit::window::WindowId, ViewportId>>,
) {
// Creating a new native window if is needed
if c_viewports.borrow().get(&pair).is_none() {
let mut builders = builders.borrow_mut();
let mut _windows = c_viewports.borrow_mut();

{
Expand Down Expand Up @@ -2205,8 +2211,8 @@ mod wgpu_integration {
Self::init_window(
pair.this,
&viewport_builder,
c_windows_id,
c_painter,
&mut c_windows_id.borrow_mut(),
&mut c_painter.borrow_mut(),
window,
&mut state.borrow_mut(),
event_loop,
Expand All @@ -2227,6 +2233,8 @@ mod wgpu_integration {
render(ctx);
});

let mut c_painter = c_painter.borrow_mut();

if let Err(err) = pollster::block_on(c_painter.set_window(pair.this, Some(&win))) {
log::error!(
"when rendering viewport_id: {}, set_window Error {err}",
Expand Down

0 comments on commit 2b8e5b5

Please sign in to comment.