Fix seg fault when using the WindowContext::on_window_should_close() API

This commit is contained in:
Mikayla 2024-01-10 11:23:18 -08:00
parent 2a09c6aad5
commit 7ef88397c9
No known key found for this signature in database
5 changed files with 13 additions and 6 deletions

View file

@ -1904,7 +1904,16 @@ impl<'a> WindowContext<'a> {
let mut this = self.to_async();
self.window
.platform_window
.on_should_close(Box::new(move || this.update(|_, cx| f(cx)).unwrap_or(true)))
.on_should_close(Box::new(move || {
this.update(|_, cx| {
// Ensure that the window is removed from the app if it's been closed.
if f(cx) {
cx.remove_window();
}
false
})
.unwrap_or(true)
}))
}
}