From b0fd400cd154d20fef33d6b4e48183e326d77c34 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Wed, 6 Jan 2021 10:17:36 +0100 Subject: [PATCH] Fix panic: 'already borrowed: BorrowMutError', graphics.rs:702 Both with_platform_window and set_scale_factor borrow the backend. --- sixtyfps_runtime/corelib/eventloop.rs | 8 +++++--- sixtyfps_runtime/corelib/graphics.rs | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/sixtyfps_runtime/corelib/eventloop.rs b/sixtyfps_runtime/corelib/eventloop.rs index 10e1dadcd..b9b07e7b1 100644 --- a/sixtyfps_runtime/corelib/eventloop.rs +++ b/sixtyfps_runtime/corelib/eventloop.rs @@ -58,7 +58,7 @@ pub trait GenericWindow { fn process_key_input(self: Rc, 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); } diff --git a/sixtyfps_runtime/corelib/graphics.rs b/sixtyfps_runtime/corelib/graphics.rs index 690a76eea..f7a6c8275 100644 --- a/sixtyfps_runtime/corelib/graphics.rs +++ b/sixtyfps_runtime/corelib/graphics.rs @@ -573,7 +573,7 @@ impl 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();