From 1cd39cf740b503b15c0fbc9e3faaabb461ae1f6b Mon Sep 17 00:00:00 2001 From: paul moore Date: Sun, 21 Jul 2024 18:31:21 -0700 Subject: [PATCH 1/3] init fix --- crates/eframe/src/native/epi_integration.rs | 4 ---- crates/eframe/src/native/glow_integration.rs | 14 +++++++++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/crates/eframe/src/native/epi_integration.rs b/crates/eframe/src/native/epi_integration.rs index c033eeef6ab..e3c8f38517d 100644 --- a/crates/eframe/src/native/epi_integration.rs +++ b/crates/eframe/src/native/epi_integration.rs @@ -266,10 +266,6 @@ impl EpiIntegration { use winit::event::{ElementState, MouseButton, WindowEvent}; match event { - WindowEvent::Destroyed => { - log::debug!("Received WindowEvent::Destroyed"); - self.close = true; - } WindowEvent::MouseInput { button: MouseButton::Left, state: ElementState::Pressed, diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index fd19f633fde..1ece058bc05 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -829,6 +829,18 @@ impl GlowWinitRunning { } } + winit::event::WindowEvent::Destroyed => { + log::debug!( + "Received WindowEvent::Destroyed for viewport {:?}", + viewport_id + ); + if viewport_id == Some(ViewportId::ROOT) { + return EventResult::Exit; + } else { + return EventResult::Wait; + } + } + _ => {} } @@ -890,7 +902,6 @@ fn change_gl_context( let not_current = if let Some(not_current_context) = not_current_gl_context.take() { not_current_context } else { - crate::profile_scope!("make_not_current"); current_gl_context .take() .unwrap() @@ -1377,6 +1388,7 @@ fn initialize_or_update_viewport( ); viewport.window = None; viewport.egui_winit = None; + viewport.gl_surface = None; } viewport.deferred_commands.append(&mut delta_commands); From c1e9bfc862894e72aff24af943910bb293120d62 Mon Sep 17 00:00:00 2001 From: paul moore Date: Sun, 21 Jul 2024 18:45:05 -0700 Subject: [PATCH 2/3] fix accidental delete of line --- crates/eframe/src/native/glow_integration.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index 1ece058bc05..13a629c54eb 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -902,6 +902,7 @@ fn change_gl_context( let not_current = if let Some(not_current_context) = not_current_gl_context.take() { not_current_context } else { + crate::profile_scope!("make_not_current"); current_gl_context .take() .unwrap() From 645f061e65e3e940e6b7683c788c23d492d877ae Mon Sep 17 00:00:00 2001 From: paul moore Date: Thu, 1 Aug 2024 21:27:37 -0700 Subject: [PATCH 3/3] fix wgpu recreate vp bug --- crates/eframe/src/native/wgpu_integration.rs | 26 +++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/crates/eframe/src/native/wgpu_integration.rs b/crates/eframe/src/native/wgpu_integration.rs index 74f4e957c70..c408cf39101 100644 --- a/crates/eframe/src/native/wgpu_integration.rs +++ b/crates/eframe/src/native/wgpu_integration.rs @@ -158,6 +158,7 @@ impl WgpuWinitApp { ViewportClass::Root, self.native_options.viewport.clone(), None, + painter, ) .initialize_window(event_loop, egui_ctx, viewport_from_window, painter); } @@ -929,8 +930,14 @@ fn render_immediate_viewport( .. } = &mut *shared.borrow_mut(); - let viewport = - initialize_or_update_viewport(viewports, ids, ViewportClass::Immediate, builder, None); + let viewport = initialize_or_update_viewport( + viewports, + ids, + ViewportClass::Immediate, + builder, + None, + painter, + ); if viewport.window.is_none() { event_loop_context::with_current_event_loop(|event_loop| { viewport.initialize_window(event_loop, egui_ctx, viewport_from_window, painter); @@ -1053,7 +1060,7 @@ fn handle_viewport_output( let ids = ViewportIdPair::from_self_and_parent(viewport_id, parent); let viewport = - initialize_or_update_viewport(viewports, ids, class, builder, viewport_ui_cb); + initialize_or_update_viewport(viewports, ids, class, builder, viewport_ui_cb, painter); if let Some(window) = viewport.window.as_ref() { let old_inner_size = window.inner_size(); @@ -1086,13 +1093,14 @@ fn handle_viewport_output( remove_viewports_not_in(viewports, painter, viewport_from_window, viewport_output); } -fn initialize_or_update_viewport( - viewports: &mut Viewports, +fn initialize_or_update_viewport<'a>( + viewports: &'a mut Viewports, ids: ViewportIdPair, class: ViewportClass, mut builder: ViewportBuilder, viewport_ui_cb: Option>, -) -> &mut Viewport { + painter: &mut egui_wgpu::winit::Painter, +) -> &'a mut Viewport { crate::profile_function!(); if builder.icon.is_none() { @@ -1137,6 +1145,12 @@ fn initialize_or_update_viewport( ); viewport.window = None; viewport.egui_winit = None; + if let Err(err) = pollster::block_on(painter.set_window(viewport.ids.this, None)) { + log::error!( + "when rendering viewport_id={:?}, set_window Error {err}", + viewport.ids.this + ); + } } viewport.deferred_commands.append(&mut delta_commands);