Skip to content

Commit

Permalink
Replace ALooper_pollAll with ALooper_pollOnce.
Browse files Browse the repository at this point in the history
ALooper_pollAll can't be called safely and is being removed from the
NDK. Replace with ALooper_pollOnce.
  • Loading branch information
DanAlbert committed May 2, 2024
1 parent 8485cea commit 89ed3b9
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions native-activity/app/src/main/cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,25 +404,28 @@ void android_main(android_app* state) {
engine.state = *(SavedState*)state->savedState;
}

while (true) {
// Read all pending events.
int events;
android_poll_source* source;

while (!state->destroyRequested) {
// Our input, sensor, and update/render logic is all driven by callbacks, so
// we don't need to use the non-blocking poll.
while ((ALooper_pollAll(-1, nullptr, &events, (void**)&source)) >= 0) {
// Process this event.
if (source != nullptr) {
source->process(state, source);
}

// Check if we are exiting.
if (state->destroyRequested != 0) {
engine_term_display(&engine);
return;
}
android_poll_source* source;
auto result = ALooper_pollOnce(-1, nullptr, nullptr,
reinterpret_cast<void**>(&source));
switch (result) {
case ALOOPER_POLL_CALLBACK:
case ALOOPER_POLL_TIMEOUT:
case ALOOPER_POLL_WAKE:
break;
case ALOOPER_EVENT_ERROR:
LOGE("ALooper_pollOnce returned an error");
break;
default:
if (source != nullptr) {
source->process(state, source);
}
break;
}
}

engine_term_display(&engine);
}
// END_INCLUDE(all)

0 comments on commit 89ed3b9

Please sign in to comment.