From 860dac69dac6f1378e8556ccd7d39afb98a572e9 Mon Sep 17 00:00:00 2001 From: pan93412 Date: Mon, 5 Jun 2023 20:57:21 +0800 Subject: [PATCH] eframe: Only run_return twice on Windows (#3053) The approach of #1889 may remove observers in a view twice, which produces the Obj-C Exception: Cannot remove an observer <...> for the key path "nextResponder" from because it is not registered as an observer. The above message can only be seen when attaching the application to debugger. Users normally see: [1] *** trace trap cargo run This commit fixes it by only running `event_loop.run_return()` twice on Windows. Besides: * We have set `ControlFlow::Exit` on `Event::LoopDestroyed`, `EventResult::Exit` and on error; therefore, it is safe to not calling `set_exit()`. * This commit also fix the persistence function in macOS. It can't store the content in Memory due to this exception. Fixed: #2768 (eframe: "App quit unexpectedly" on macOS) Signed-off-by: pan93412 --- crates/eframe/src/native/run.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/crates/eframe/src/native/run.rs b/crates/eframe/src/native/run.rs index 554531681..2f3daceb4 100644 --- a/crates/eframe/src/native/run.rs +++ b/crates/eframe/src/native/run.rs @@ -238,9 +238,15 @@ fn run_and_return( // On Windows this clears out events so that we can later create another window. // See https://github.com/emilk/egui/pull/1889 for details. - event_loop.run_return(|_, _, control_flow| { - control_flow.set_exit(); - }); + // + // Note that this approach may cause issues on macOS (emilk/egui#2768); therefore, + // we only apply this approach on Windows to minimize the affect. + #[cfg(windows)] + { + event_loop.run_return(|_, _, control_flow| { + control_flow.set_exit(); + }); + } returned_result }