Fix BorrowMutError
@@ -220,9 +220,9 @@ impl WindowBuilder {
// For some reason piet needs a mutable context, so give it one I guess.
let mut context = context.clone();
let mut piet_context = Piet::new(&mut context);
- let anim = state
- .handler
- .borrow_mut()
+
+ if let Ok(mut handler_borrow) = state.handler.try_borrow_mut() {
+ let anim = handler_borrow
.paint(&mut piet_context, &mut ctx);
if let Err(e) = piet_context.finish() {
eprintln!("piet error on render: {:?}", e);
@@ -233,6 +233,8 @@ impl WindowBuilder {
}
}
+ }
+
Inhibit(false)
}));
@@ -538,14 +540,13 @@ impl<'a> WinCtx<'a> for WinCtxImpl<'a> {
gdk::threads_add_timeout(interval, move || {
if let Some(state) = handle.state.upgrade() {
+ if let Ok(mut handler_borrow) = state.handler.try_borrow_mut() {
let mut ctx = WinCtxImpl::from(&handle);
-
- state
- .handler
- .borrow_mut()
- .timer(TimerToken::new(token), &mut ctx);
+ handler_borrow.timer(TimerToken::new(token), &mut ctx);
+ return false;
}
- false
+ }
+ true
});
TimerToken::new(token)
