Fix panic: 'already borrowed: BorrowMutError', graphics.rs:702

Both with_platform_window and set_scale_factor borrow the backend.
This commit is contained in:
Olivier Goffart 2021-01-06 10:17:36 +01:00 committed by Simon Hausmann
parent 769ad146e7
commit b0fd400cd1
2 changed files with 6 additions and 4 deletions

View file

@ -58,7 +58,7 @@ pub trait GenericWindow {
fn process_key_input(self: Rc<Self>, event: &KeyEvent);
/// Calls the `callback` function with the underlying winit::Window that this
/// GenericWindow backs.
fn with_platform_window(&self, callback: &dyn Fn(&winit::window::Window));
fn with_platform_window(&self, callback: &mut dyn FnMut(&winit::window::Window));
/// Requests for the window to be mapped to the screen.
///
/// Arguments:
@ -271,9 +271,11 @@ impl EventLoop {
if let Some(Some(window)) =
windows.borrow().get(&window_id).map(|weakref| weakref.upgrade())
{
window.with_platform_window(&|platform_window| {
window.set_scale_factor(platform_window.scale_factor() as f32);
let mut sf = 1.;
window.with_platform_window(&mut |platform_window| {
sf = platform_window.scale_factor();
});
window.set_scale_factor(sf as f32);
window.set_width(size.width as f32);
window.set_height(size.height as f32);
}

View file

@ -573,7 +573,7 @@ impl<Backend: GraphicsBackend> crate::eventloop::GenericWindow for GraphicsWindo
}
}
fn with_platform_window(&self, callback: &dyn Fn(&winit::window::Window)) {
fn with_platform_window(&self, callback: &mut dyn FnMut(&winit::window::Window)) {
let map_state = self.map_state.borrow();
let window = map_state.as_mapped();
let backend = window.backend.borrow();