Skip to content

Commit ece52f2

Browse files
committed
Replace ALooper_pollAll with ALooper_pollOnce.
ALooper_pollAll can't be called safely and is being removed from the NDK. Replace with ALooper_pollOnce.
1 parent 8485cea commit ece52f2

File tree

1 file changed

+11
-15
lines changed
  • native-activity/app/src/main/cpp

1 file changed

+11
-15
lines changed

native-activity/app/src/main/cpp/main.cpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -404,25 +404,21 @@ void android_main(android_app* state) {
404404
engine.state = *(SavedState*)state->savedState;
405405
}
406406

407-
while (true) {
408-
// Read all pending events.
409-
int events;
410-
android_poll_source* source;
411-
407+
while (!state->destroyRequested) {
412408
// Our input, sensor, and update/render logic is all driven by callbacks, so
413409
// we don't need to use the non-blocking poll.
414-
while ((ALooper_pollAll(-1, nullptr, &events, (void**)&source)) >= 0) {
415-
// Process this event.
416-
if (source != nullptr) {
417-
source->process(state, source);
418-
}
410+
android_poll_source* source = nullptr;
411+
auto result = ALooper_pollOnce(-1, nullptr, nullptr,
412+
reinterpret_cast<void**>(&source));
413+
if (result == ALOOPER_POLL_ERROR) {
414+
fatal("ALooper_pollOnce returned an error");
415+
}
419416

420-
// Check if we are exiting.
421-
if (state->destroyRequested != 0) {
422-
engine_term_display(&engine);
423-
return;
424-
}
417+
if (source != nullptr) {
418+
source->process(state, source);
425419
}
426420
}
421+
422+
engine_term_display(&engine);
427423
}
428424
// END_INCLUDE(all)

0 commit comments

Comments
 (0)