Fix crash when running iPad build on macOS

This commit is contained in:
Arend van Beelen jr 2023-11-22 13:14:51 +01:00 committed by GitHub
parent 7bed5eecfd
commit d3ca685b77
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 5 deletions

View file

@ -11,6 +11,7 @@ Unreleased` header.
# Unreleased # Unreleased
- Fix crash when running iOS app on macOS.
- On X11, check common alternative cursor names when loading cursor. - On X11, check common alternative cursor names when loading cursor.
- On Windows, fix so `drag_window` and `drag_resize_window` can be called from another thread. - On Windows, fix so `drag_window` and `drag_resize_window` can be called from another thread.
- On Windows, fix `set_control_flow` in `AboutToWait` not being taken in account. - On Windows, fix `set_control_flow` in `AboutToWait` not being taken in account.

View file

@ -200,6 +200,10 @@ impl AppState {
) )
} }
fn has_terminated(&self) -> bool {
matches!(self.state(), AppStateImpl::Terminated)
}
fn will_launch_transition(&mut self, queued_event_handler: Box<dyn EventHandler>) { fn will_launch_transition(&mut self, queued_event_handler: Box<dyn EventHandler>) {
let (queued_windows, queued_events, queued_gpu_redraws) = match self.take_state() { let (queued_windows, queued_events, queued_gpu_redraws) = match self.take_state() {
AppStateImpl::NotLaunched { AppStateImpl::NotLaunched {
@ -243,7 +247,7 @@ impl AppState {
fn wakeup_transition(&mut self) -> Option<EventWrapper> { fn wakeup_transition(&mut self) -> Option<EventWrapper> {
// before `AppState::did_finish_launching` is called, pretend there is no running // before `AppState::did_finish_launching` is called, pretend there is no running
// event loop. // event loop.
if !self.has_launched() { if !self.has_launched() || self.has_terminated() {
return None; return None;
} }
@ -390,7 +394,7 @@ impl AppState {
} }
fn events_cleared_transition(&mut self) { fn events_cleared_transition(&mut self) {
if !self.has_launched() { if !self.has_launched() || self.has_terminated() {
return; return;
} }
let (waiting_event_handler, old) = match self.take_state() { let (waiting_event_handler, old) = match self.take_state() {
@ -586,6 +590,10 @@ pub(crate) fn handle_nonuser_events<I: IntoIterator<Item = EventWrapper>>(
events: I, events: I,
) { ) {
let mut this = AppState::get_mut(mtm); let mut this = AppState::get_mut(mtm);
if this.has_terminated() {
return;
}
let (mut event_handler, active_control_flow, processing_redraws) = let (mut event_handler, active_control_flow, processing_redraws) =
match this.try_user_callback_transition() { match this.try_user_callback_transition() {
UserCallbackTransitionResult::ReentrancyPrevented { queued_events } => { UserCallbackTransitionResult::ReentrancyPrevented { queued_events } => {
@ -737,7 +745,7 @@ fn handle_user_events(mtm: MainThreadMarker) {
pub fn handle_main_events_cleared(mtm: MainThreadMarker) { pub fn handle_main_events_cleared(mtm: MainThreadMarker) {
let mut this = AppState::get_mut(mtm); let mut this = AppState::get_mut(mtm);
if !this.has_launched() { if !this.has_launched() || this.has_terminated() {
return; return;
} }
match this.state_mut() { match this.state_mut() {

View file

@ -289,7 +289,7 @@ fn setup_control_flow_observers() {
#[allow(non_upper_case_globals)] #[allow(non_upper_case_globals)]
match activity { match activity {
kCFRunLoopBeforeWaiting => app_state::handle_main_events_cleared(mtm), kCFRunLoopBeforeWaiting => app_state::handle_main_events_cleared(mtm),
kCFRunLoopExit => unimplemented!(), // not expected to ever happen kCFRunLoopExit => {} // may happen when running on macOS
_ => unreachable!(), _ => unreachable!(),
} }
} }
@ -304,7 +304,7 @@ fn setup_control_flow_observers() {
#[allow(non_upper_case_globals)] #[allow(non_upper_case_globals)]
match activity { match activity {
kCFRunLoopBeforeWaiting => app_state::handle_events_cleared(mtm), kCFRunLoopBeforeWaiting => app_state::handle_events_cleared(mtm),
kCFRunLoopExit => unimplemented!(), // not expected to ever happen kCFRunLoopExit => {} // may happen when running on macOS
_ => unreachable!(), _ => unreachable!(),
} }
} }