diff --git a/blade-graphics/src/vulkan/command.rs b/blade-graphics/src/vulkan/command.rs index 07c051c0..8833e627 100644 --- a/blade-graphics/src/vulkan/command.rs +++ b/blade-graphics/src/vulkan/command.rs @@ -297,6 +297,10 @@ impl super::CommandEncoder { } pub fn present(&mut self, frame: super::Frame) { + if frame.acquire_semaphore == vk::Semaphore::null() { + return; + } + assert_eq!(self.present, None); let wa = &self.device.workarounds; self.present = Some(super::Presentation { diff --git a/blade-graphics/src/vulkan/init.rs b/blade-graphics/src/vulkan/init.rs index 6b79babc..949814eb 100644 --- a/blade-graphics/src/vulkan/init.rs +++ b/blade-graphics/src/vulkan/init.rs @@ -806,16 +806,29 @@ impl super::Context { pub fn acquire_frame(&self) -> super::Frame { let mut surface = self.surface.as_ref().unwrap().lock().unwrap(); let acquire_semaphore = surface.next_semaphore; - let (index, _suboptimal) = unsafe { - surface - .extension - .acquire_next_image(surface.swapchain, !0, acquire_semaphore, vk::Fence::null()) - .unwrap() - }; - surface.next_semaphore = mem::replace( - &mut surface.frames[index as usize].acquire_semaphore, - acquire_semaphore, - ); - surface.frames[index as usize] + match unsafe { + surface.extension.acquire_next_image( + surface.swapchain, + !0, + acquire_semaphore, + vk::Fence::null(), + ) + } { + Ok((index, _suboptimal)) => { + surface.next_semaphore = mem::replace( + &mut surface.frames[index as usize].acquire_semaphore, + acquire_semaphore, + ); + surface.frames[index as usize] + } + Err(vk::Result::ERROR_OUT_OF_DATE_KHR) => { + log::warn!("Acquire failed because the surface is out of date"); + super::Frame { + acquire_semaphore: vk::Semaphore::null(), + ..surface.frames[0] + } + } + Err(other) => panic!("Aquire image error {}", other), + } } }