Skip to content

Commit

Permalink
Fix examples crashing when minimized (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
hakolao authored Feb 12, 2024
1 parent 244565b commit a14b0c7
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 59 deletions.
16 changes: 7 additions & 9 deletions examples/demo_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
// according to those terms.

use egui_winit_vulkano::{egui, Gui, GuiConfig};
use vulkano::sync::{self, GpuFuture};
use vulkano_util::{
context::{VulkanoConfig, VulkanoContext},
window::{VulkanoWindows, WindowDescriptor},
Expand Down Expand Up @@ -119,19 +118,18 @@ pub fn main() {

// Render UI
// Acquire swapchain future
let before_future = match renderer.acquire() {
Ok(future) => future,
match renderer.acquire() {
Ok(future) => {
let after_future =
gui.draw_on_image(future, renderer.swapchain_image_view());
// Present swapchain
renderer.present(after_future, true);
}
Err(vulkano::VulkanError::OutOfDate) => {
renderer.resize();
sync::now(context.device().clone()).boxed()
}
Err(e) => panic!("Failed to acquire swapchain future: {}", e),
};
// Render gui
let after_future =
gui.draw_on_image(before_future, renderer.swapchain_image_view());
// Present swapchain
renderer.present(after_future, true);
}
Event::MainEventsCleared => {
renderer.window().request_redraw();
Expand Down
17 changes: 8 additions & 9 deletions examples/minimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

use egui::{ScrollArea, TextEdit, TextStyle};
use egui_winit_vulkano::{egui, Gui, GuiConfig};
use vulkano::sync::{self, GpuFuture};
use vulkano_util::{
context::{VulkanoConfig, VulkanoContext},
window::{VulkanoWindows, WindowDescriptor},
Expand Down Expand Up @@ -98,19 +97,19 @@ pub fn main() {
});
// Render UI
// Acquire swapchain future
let before_future = match renderer.acquire() {
Ok(future) => future,
match renderer.acquire() {
Ok(future) => {
// Render gui
let after_future =
gui.draw_on_image(future, renderer.swapchain_image_view());
// Present swapchain
renderer.present(after_future, true);
}
Err(vulkano::VulkanError::OutOfDate) => {
renderer.resize();
sync::now(context.device().clone()).boxed()
}
Err(e) => panic!("Failed to acquire swapchain future: {}", e),
};
// Render gui
let after_future =
gui.draw_on_image(before_future, renderer.swapchain_image_view());
// Present swapchain
renderer.present(after_future, true);
}
Event::MainEventsCleared => {
renderer.window().request_redraw();
Expand Down
18 changes: 9 additions & 9 deletions examples/multisample.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use vulkano::{
DynamicState, GraphicsPipeline, PipelineLayout, PipelineShaderStageCreateInfo,
},
render_pass::{Framebuffer, FramebufferCreateInfo, RenderPass, Subpass},
sync::{self, GpuFuture},
sync::GpuFuture,
};
use vulkano_util::{
context::{VulkanoConfig, VulkanoContext},
Expand Down Expand Up @@ -129,19 +129,19 @@ pub fn main() {
});
// Render
// Acquire swapchain future
let before_future = match renderer.acquire() {
Ok(future) => future,
match renderer.acquire() {
Ok(future) => {
// Render
let after_future =
pipeline.render(future, renderer.swapchain_image_view(), &mut gui);
// Present swapchain
renderer.present(after_future, true);
}
Err(vulkano::VulkanError::OutOfDate) => {
renderer.resize();
sync::now(context.device().clone()).boxed()
}
Err(e) => panic!("Failed to acquire swapchain future: {}", e),
};
// Render
let after_future =
pipeline.render(before_future, renderer.swapchain_image_view(), &mut gui);
// Present swapchain
renderer.present(after_future, true);
}
Event::MainEventsCleared => {
renderer.window().request_redraw();
Expand Down
17 changes: 8 additions & 9 deletions examples/paint_callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use vulkano::{
layout::PipelineDescriptorSetLayoutCreateInfo,
DynamicState, GraphicsPipeline, PipelineLayout, PipelineShaderStageCreateInfo,
},
sync::{self, GpuFuture},
};
use vulkano_util::{
context::{VulkanoConfig, VulkanoContext},
Expand Down Expand Up @@ -120,19 +119,19 @@ pub fn main() {
});
// Render UI
// Acquire swapchain future
let before_future = match renderer.acquire() {
Ok(future) => future,
match renderer.acquire() {
Ok(future) => {
// Render gui
let after_future =
gui.draw_on_image(future, renderer.swapchain_image_view());
// Present swapchain
renderer.present(after_future, true);
}
Err(vulkano::VulkanError::OutOfDate) => {
renderer.resize();
sync::now(context.device().clone()).boxed()
}
Err(e) => panic!("Failed to acquire swapchain future: {}", e),
};
// Render gui
let after_future =
gui.draw_on_image(before_future, renderer.swapchain_image_view());
// Present swapchain
renderer.present(after_future, true);
}
Event::MainEventsCleared => {
renderer.window().request_redraw();
Expand Down
21 changes: 10 additions & 11 deletions examples/subpass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use vulkano::{
DynamicState, GraphicsPipeline, PipelineLayout, PipelineShaderStageCreateInfo,
},
render_pass::{Framebuffer, FramebufferCreateInfo, RenderPass, Subpass},
sync::{self, GpuFuture},
sync::GpuFuture,
};
use vulkano_util::{
context::{VulkanoConfig, VulkanoContext},
Expand Down Expand Up @@ -124,21 +124,20 @@ pub fn main() {
});

// Acquire swapchain future
let before_future = match renderer.acquire() {
Ok(future) => future,
match renderer.acquire() {
Ok(future) => {
// Render gui
let after_future =
gui_pipeline.render(future, renderer.swapchain_image_view(), &mut gui);

// Present swapchain
renderer.present(after_future, true);
}
Err(vulkano::VulkanError::OutOfDate) => {
renderer.resize();
sync::now(context.device().clone()).boxed()
}
Err(e) => panic!("Failed to acquire swapchain future: {}", e),
};

// Render gui
let after_future =
gui_pipeline.render(before_future, renderer.swapchain_image_view(), &mut gui);

// Present swapchain
renderer.present(after_future, true);
}
Event::MainEventsCleared => {
renderer.window().request_redraw();
Expand Down
23 changes: 11 additions & 12 deletions examples/wholesome/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use vulkano::{
format::Format,
image::{view::ImageView, Image, ImageCreateInfo, ImageType, ImageUsage},
memory::allocator::AllocationCreateInfo,
sync::{self, GpuFuture},
};
use vulkano_util::{
context::{VulkanoConfig, VulkanoContext},
Expand Down Expand Up @@ -221,22 +220,22 @@ pub fn main() {
});
// Render UI
// Acquire swapchain future
let before_future = match renderer.acquire() {
Ok(future) => future,
match renderer.acquire() {
Ok(future) => {
// Draw scene
let after_scene_draw =
scene_render_pipeline.render(future, scene_image.clone());
// Render gui
let after_future =
gui.draw_on_image(after_scene_draw, renderer.swapchain_image_view());
// Present swapchain
renderer.present(after_future, true);
}
Err(vulkano::VulkanError::OutOfDate) => {
renderer.resize();
sync::now(context.device().clone()).boxed()
}
Err(e) => panic!("Failed to acquire swapchain future: {}", e),
};
// Draw scene
let after_scene_draw =
scene_render_pipeline.render(before_future, scene_image.clone());
// Render gui
let after_future =
gui.draw_on_image(after_scene_draw, renderer.swapchain_image_view());
// Present swapchain
renderer.present(after_future, true);

// Update fps & dt
time.update();
Expand Down

0 comments on commit a14b0c7

Please sign in to comment.