From a4747242b5be329c9b56567c13cb69140ed3a6e1 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Mon, 4 Dec 2023 15:16:38 +0100 Subject: [PATCH] Fix crash on Android --- crates/eframe/src/native/wgpu_integration.rs | 26 ++++++++++++++------ 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/crates/eframe/src/native/wgpu_integration.rs b/crates/eframe/src/native/wgpu_integration.rs index 3f9cf14e983..ffca427b422 100644 --- a/crates/eframe/src/native/wgpu_integration.rs +++ b/crates/eframe/src/native/wgpu_integration.rs @@ -388,13 +388,25 @@ impl WinitApp for WgpuWinitApp { self.init_run_state(egui_ctx, event_loop, storage, window, builder)? }; - EventResult::RepaintNow( - running.shared.borrow().viewports[&ViewportId::ROOT] - .window - .as_ref() - .unwrap() - .id(), - ) + let SharedState { + egui_ctx, + viewports, + painter, + viewport_from_window, + .. + } = &mut *running.shared.borrow_mut(); + + let viewport = viewports.get_mut(&ViewportId::ROOT).unwrap(); + + if viewport.window.is_none() { + viewport.init_window(egui_ctx, viewport_from_window, painter, event_loop); + } + + if let Some(window) = &viewport.window { + EventResult::RepaintNow(window.id()) + } else { + EventResult::Wait + } } winit::event::Event::Suspended => {