Skip to content

Commit

Permalink
Fix crash when running iPad build on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
arendjr authored and kchibisov committed Nov 24, 2023
1 parent f968e64 commit 06cec06
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Unreleased` header.

# Unreleased

- Fix crash when running iOS app on macOS.
- 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 `set_control_flow` in `AboutToWait` not being taken in account.
Expand Down
14 changes: 11 additions & 3 deletions src/platform_impl/ios/app_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>) {
let (queued_windows, queued_events, queued_gpu_redraws) = match self.take_state() {
AppStateImpl::NotLaunched {
Expand Down Expand Up @@ -243,7 +247,7 @@ impl AppState {
fn wakeup_transition(&mut self) -> Option<EventWrapper> {
// before `AppState::did_finish_launching` is called, pretend there is no running
// event loop.
if !self.has_launched() {
if !self.has_launched() || self.has_terminated() {
return None;
}

Expand Down Expand Up @@ -390,7 +394,7 @@ impl AppState {
}

fn events_cleared_transition(&mut self) {
if !self.has_launched() {
if !self.has_launched() || self.has_terminated() {
return;
}
let (waiting_event_handler, old) = match self.take_state() {
Expand Down Expand Up @@ -586,6 +590,10 @@ pub(crate) fn handle_nonuser_events<I: IntoIterator<Item = EventWrapper>>(
events: I,
) {
let mut this = AppState::get_mut(mtm);
if this.has_terminated() {
return;
}

let (mut event_handler, active_control_flow, processing_redraws) =
match this.try_user_callback_transition() {
UserCallbackTransitionResult::ReentrancyPrevented { queued_events } => {
Expand Down Expand Up @@ -737,7 +745,7 @@ fn handle_user_events(mtm: MainThreadMarker) {

pub fn handle_main_events_cleared(mtm: MainThreadMarker) {
let mut this = AppState::get_mut(mtm);
if !this.has_launched() {
if !this.has_launched() || this.has_terminated() {
return;
}
match this.state_mut() {
Expand Down
4 changes: 2 additions & 2 deletions src/platform_impl/ios/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ fn setup_control_flow_observers() {
#[allow(non_upper_case_globals)]
match activity {
kCFRunLoopBeforeWaiting => app_state::handle_main_events_cleared(mtm),
kCFRunLoopExit => unimplemented!(), // not expected to ever happen
kCFRunLoopExit => {} // may happen when running on macOS
_ => unreachable!(),
}
}
Expand All @@ -304,7 +304,7 @@ fn setup_control_flow_observers() {
#[allow(non_upper_case_globals)]
match activity {
kCFRunLoopBeforeWaiting => app_state::handle_events_cleared(mtm),
kCFRunLoopExit => unimplemented!(), // not expected to ever happen
kCFRunLoopExit => {} // may happen when running on macOS
_ => unreachable!(),
}
}
Expand Down

0 comments on commit 06cec06

Please sign in to comment.