Fix Android crash on resume (#3847)
<!-- Please read the "Making a PR" section of [`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/master/CONTRIBUTING.md) before opening a Pull Request! * Keep your PR:s small and focused. * If applicable, add a screenshot or gif. * If it is a non-trivial addition, consider adding a demo for it to `egui_demo_lib`, or a new example. * Do NOT open PR:s from your `master` branch, as that makes it hard for maintainers to add commits to your PR. * Remember to run `cargo fmt` and `cargo cranky`. * Open the PR as a draft until you have self-reviewed it and run `./scripts/check.sh`. * When you have addressed a PR comment, mark it as resolved. Please be patient! I will review your PR, but my time is limited! --> Added Viewport reinitialization and Window recreation for Android on resume event. Closes <https://github.com/emilk/egui/issues/3674>. https://github.com/emilk/egui/assets/95014675/7bc51ea5-3f63-4422-b5a0-ce8291612982
This commit is contained in:
parent
2d725d157f
commit
e46b0018b9
|
|
@ -139,6 +139,32 @@ impl WgpuWinitApp {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "android")]
|
||||
fn recreate_window(
|
||||
&self,
|
||||
event_loop: &EventLoopWindowTarget<UserEvent>,
|
||||
running: &WgpuWinitRunning,
|
||||
) {
|
||||
let SharedState {
|
||||
egui_ctx,
|
||||
viewports,
|
||||
viewport_from_window,
|
||||
painter,
|
||||
..
|
||||
} = &mut *running.shared.borrow_mut();
|
||||
|
||||
initialize_or_update_viewport(
|
||||
egui_ctx,
|
||||
viewports,
|
||||
ViewportIdPair::ROOT,
|
||||
ViewportClass::Root,
|
||||
self.native_options.viewport.clone(),
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.initialize_window(event_loop, egui_ctx, viewport_from_window, painter);
|
||||
}
|
||||
|
||||
#[cfg(target_os = "android")]
|
||||
fn drop_window(&mut self) -> Result<(), egui_wgpu::WgpuError> {
|
||||
if let Some(running) = &mut self.running {
|
||||
|
|
@ -386,6 +412,8 @@ impl WinitApp for WgpuWinitApp {
|
|||
log::debug!("Event::Resumed");
|
||||
|
||||
let running = if let Some(running) = &self.running {
|
||||
#[cfg(target_os = "android")]
|
||||
self.recreate_window(event_loop, running);
|
||||
running
|
||||
} else {
|
||||
let storage = epi_integration::create_storage(
|
||||
|
|
|
|||
Loading…
Reference in New Issue