prevents crashing when reconfiguring with an in use view/image/swapchain something, moved the configure event to after the image has been displayed and resources are released, thats all

This commit is contained in:
Halbear 2026-09-05 20:21:15 +01:00
parent b02f629bd3
commit 1519a1c065

View file

@ -1176,10 +1176,13 @@ impl Renderer {
} }
pub(crate) fn render(&mut self, window: &Arc<Window>) -> anyhow::Result<()> { pub(crate) fn render(&mut self, window: &Arc<Window>) -> anyhow::Result<()> {
window.request_redraw(); window.request_redraw();
let mut resize_renderer = false;
let output = match self.surface.get_current_texture() { let output = match self.surface.get_current_texture() {
wgpu::CurrentSurfaceTexture::Success(surface_texture) => surface_texture, wgpu::CurrentSurfaceTexture::Success(surface_texture) => surface_texture,
wgpu::CurrentSurfaceTexture::Suboptimal(surface_texture) => { wgpu::CurrentSurfaceTexture::Suboptimal(surface_texture) => {
self.surface.configure(&self.device, &self.config); resize_renderer = true; //moved reconfigure to avoid a crash when resizing window
surface_texture surface_texture
} }
wgpu::CurrentSurfaceTexture::Timeout wgpu::CurrentSurfaceTexture::Timeout
@ -1257,6 +1260,21 @@ impl Renderer {
output.present(); output.present();
if(resize_renderer){
std::mem::drop(view); //idk how this would affect a multi-pass system like deferred rendering, but this makes sure it's not gonna collide with resizing the swap chain or whatever wGPU does
self.surface.configure(&self.device, &self.config);
/*
also in this snippet call the functions to
a: resize window resolution
b: resize projection
currently when you resize the window the projection matrix is not updated
and therefore it gets very skewed and weird looking if you resize the current
small window to a big screen like mine(halbear) which is 3440x1440
i would add it myself but i don't know wGPU or rust all that well sooooo
*/
}
Ok(()) Ok(())
} }
} }