Skip to content

Commit

Permalink
Fix Android crash on resume (#3847)
Browse files Browse the repository at this point in the history
<!--
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 <#3674>.


https://github.com/emilk/egui/assets/95014675/7bc51ea5-3f63-4422-b5a0-ce8291612982
  • Loading branch information
Garoven authored Jan 22, 2024
1 parent 2d725d1 commit e46b001
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions crates/eframe/src/native/wgpu_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit e46b001

Please sign in to comment.