Skip to content

Commit 9e8c85c

Browse files
MarijnS95rib
authored andcommitted
Assert that the thread Looper matches the main one
1 parent a97cf1c commit 9e8c85c

File tree

2 files changed

+9
-3
lines changed
  • android-activity/src

2 files changed

+9
-3
lines changed

android-activity/src/game_activity/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,11 @@ impl AndroidAppInner {
295295

296296
unsafe {
297297
let native_app = &self.native_app;
298+
assert_eq!(
299+
ndk_sys::ALooper_forThread(),
300+
(*native_app.as_ptr()).looper,
301+
"Application tried to poll events from non-main thread"
302+
);
298303

299304
let mut fd: i32 = 0;
300305
let mut events: i32 = 0;
@@ -590,7 +595,7 @@ impl AndroidAppInner {
590595
let mut guard = self.input_receiver.lock().unwrap();
591596

592597
// Make sure we don't hand out more than one receiver at a time because
593-
// turning the reciever into an interator will perform a swap_buffers
598+
// turning the receiver into an iterator will perform a swap_buffers
594599
// for the buffered input events which shouldn't happen while we're in
595600
// the middle of iterating events
596601
if let Some(receiver) = &*guard {

android-activity/src/native_activity/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,9 @@ impl AndroidAppInner {
201201
};
202202

203203
trace!("Calling ALooper_pollAll, timeout = {timeout_milliseconds}");
204-
assert!(
205-
!ndk_sys::ALooper_forThread().is_null(),
204+
assert_eq!(
205+
ndk_sys::ALooper_forThread(),
206+
self.looper.ptr,
206207
"Application tried to poll events from non-main thread"
207208
);
208209
let id = ndk_sys::ALooper_pollAll(

0 commit comments

Comments
 (0)