Skip to content

Commit

Permalink
Merge pull request #1504 from hannobraun/render
Browse files Browse the repository at this point in the history
Fix app crashing, if it is minimized too long
  • Loading branch information
hannobraun authored Jan 12, 2023
2 parents cdaceb9 + ea86ad5 commit 4d64a65
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion crates/fj-viewer/src/graphics/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ impl Renderer {
Ok(surface_texture) => surface_texture,
Err(wgpu::SurfaceError::Timeout) => {
// I'm seeing this all the time now (as in, multiple times per
// microsecond), which `PresentMode::AutoVsync`. Not sure what's
// microsecond), with `PresentMode::AutoVsync`. Not sure what's
// going on, but for now, it works to just ignore it.
//
// Issues for reference:
Expand Down
15 changes: 14 additions & 1 deletion crates/fj-viewer/src/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub struct Gui {
context: egui::Context,
renderer: egui_wgpu::Renderer,
options: Options,
egui_output: Option<egui::FullOutput>,
}

impl Gui {
Expand Down Expand Up @@ -71,6 +72,7 @@ impl Gui {
context,
renderer,
options: Options::default(),
egui_output: None,
}
}

Expand Down Expand Up @@ -270,6 +272,15 @@ impl Gui {
});
}

// Even though the output is not used here, `end_frame` must be called
// at the end of this function. If we don't, and we get into a situation
// where `update` is called, but `prepare_draw` isn't for a while, the
// context will keep accumulating output.
//
// That might end up being too much output to handle. This can lead to
// a crash, because a index/vertex buffer gets too full.
self.egui_output = Some(self.context.end_frame());

new_model_path
}

Expand All @@ -280,7 +291,9 @@ impl Gui {
encoder: &mut wgpu::CommandEncoder,
screen_descriptor: &egui_wgpu::renderer::ScreenDescriptor,
) -> Vec<egui::ClippedPrimitive> {
let egui_output = self.context.end_frame();
let Some(egui_output) = self.egui_output.take() else {
return Vec::new()
};
let clipped_primitives = self.context.tessellate(egui_output.shapes);

for (id, image_delta) in &egui_output.textures_delta.set {
Expand Down

0 comments on commit 4d64a65

Please sign in to comment.