mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-25 23:01:30 +11:00
Prevent callbacks from being destroyed too early
This commit is contained in:
parent
77cd3adb01
commit
94f6294c0a
|
@ -259,7 +259,7 @@ fn add_event<T: 'static, E, F>(
|
||||||
{
|
{
|
||||||
let elrs = elrs.clone();
|
let elrs = elrs.clone();
|
||||||
|
|
||||||
target.add_event_listener_with_callback(event, Closure::wrap(Box::new(move |event: E| {
|
let closure = Closure::wrap(Box::new(move |event: E| {
|
||||||
// Don't capture the event if the events loop has been destroyed
|
// Don't capture the event if the events loop has been destroyed
|
||||||
match &*elrs.runner.borrow() {
|
match &*elrs.runner.borrow() {
|
||||||
Some(ref runner) if runner.control == ControlFlow::Exit => return,
|
Some(ref runner) if runner.control == ControlFlow::Exit => return,
|
||||||
|
@ -272,7 +272,10 @@ fn add_event<T: 'static, E, F>(
|
||||||
event_ref.cancel_bubble();
|
event_ref.cancel_bubble();
|
||||||
|
|
||||||
handler(&elrs, event);
|
handler(&elrs, event);
|
||||||
}) as Box<FnMut(E)>).as_ref().unchecked_ref());
|
}) as Box<FnMut(E)>);
|
||||||
|
|
||||||
|
target.add_event_listener_with_callback(event, &closure.as_ref().unchecked_ref());
|
||||||
|
closure.forget(); // TODO: don't leak this.
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> ELRShared<T> {
|
impl<T> ELRShared<T> {
|
||||||
|
|
|
@ -69,12 +69,13 @@ impl Window {
|
||||||
let runner = target.runner.clone();
|
let runner = target.runner.clone();
|
||||||
let redraw = Box::new(move || {
|
let redraw = Box::new(move || {
|
||||||
let runner = runner.clone();
|
let runner = runner.clone();
|
||||||
window().request_animation_frame(Closure::wrap(Box::new(move |_: f64| {
|
let closure = Closure::once_into_js(move |_: f64| {
|
||||||
runner.send_event(Event::WindowEvent {
|
runner.send_event(Event::WindowEvent {
|
||||||
window_id: RootWI(WindowId),
|
window_id: RootWI(WindowId),
|
||||||
event: WindowEvent::RedrawRequested
|
event: WindowEvent::RedrawRequested
|
||||||
});
|
});
|
||||||
}) as Box<Fn(f64)>).as_ref().unchecked_ref());
|
});
|
||||||
|
window().request_animation_frame(closure.as_ref().unchecked_ref());
|
||||||
});
|
});
|
||||||
|
|
||||||
let window = Window {
|
let window = Window {
|
||||||
|
|
Loading…
Reference in a new issue