Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix WindowEvent::Destroyed might fire twice on macOS #831

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/mac-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tao": patch
---

On macOS, fix `WindowEvent::Destroyed` may fire twice.

17 changes: 2 additions & 15 deletions src/platform_impl/macos/util/async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,7 @@ use objc::{

use crate::{
dpi::LogicalSize,
event::{Event, WindowEvent},
platform_impl::platform::{
app_state::AppState,
event::EventWrapper,
ffi,
util::IdRef,
window::{get_window_id, SharedState},
},
window::WindowId,
platform_impl::platform::{ffi, util::IdRef, window::SharedState},
};

pub fn is_main_thread() -> bool {
Expand Down Expand Up @@ -251,14 +243,9 @@ pub unsafe fn set_focus(ns_window: id) {
// through the `IdRef` because otherwise it would dereference free'd memory
pub unsafe fn close_async(ns_window: IdRef) {
let ns_window = MainThreadSafe(ns_window);
Queue::main().exec_async(move || {
run_on_main(move || {
autoreleasepool(move || {
ns_window.close();
let event = Event::WindowEvent {
window_id: WindowId(get_window_id(*ns_window.0)),
event: WindowEvent::Destroyed,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was this event removed? is the destroyed event sent somewhere else?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a workaround we did before.
It should be sent by windowWillClose in window's delegate.

};
AppState::queue_event(EventWrapper::StaticEvent(event));
});
});
}
Expand Down