Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement a workaround for "Map callback was leaked" #375

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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