Skip to content

Commit

Permalink
Implement a workaround for "Map callback was leaked"
Browse files Browse the repository at this point in the history
  • Loading branch information
DJMcNab committed Oct 8, 2023
1 parent 1ef6724 commit f6adeb7
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,29 +82,35 @@ impl RenderContext {
alpha_mode: wgpu::CompositeAlphaMode::Auto,
view_formats: vec![],
};
surface.configure(&self.devices[dev_id].device, &config);
Ok(RenderSurface {
let surface = RenderSurface {
surface,
config,
dev_id,
format,
})
};
self.configure_surface(&surface);
Ok(surface)
}

/// Resizes the surface to the new dimensions.
pub fn resize_surface(&self, surface: &mut RenderSurface, width: u32, height: u32) {
surface.config.width = width;
surface.config.height = height;
surface
.surface
.configure(&self.devices[surface.dev_id].device, &surface.config);
self.configure_surface(surface);
}

pub fn set_present_mode(&self, surface: &mut RenderSurface, present_mode: wgpu::PresentMode) {
surface.config.present_mode = present_mode;
surface
.surface
.configure(&self.devices[surface.dev_id].device, &surface.config);
self.configure_surface(surface);
}

fn configure_surface(&self, surface: &RenderSurface) {
let device = &self.devices[surface.dev_id].device;
// Temporary workaround for https://github.com/gfx-rs/wgpu/issues/4214
// It's still possible for this to panic if the device is being used on another thread
// but this unbreaks most current users
device.poll(wgpu::MaintainBase::Wait);
surface.surface.configure(device, &surface.config);
}

/// Finds or creates a compatible device handle id.
Expand Down

0 comments on commit f6adeb7

Please sign in to comment.