From 89ed3b98955c4cad8ec4ba7513f53e7b84482f97 Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Wed, 1 May 2024 14:54:13 -0700 Subject: [PATCH] Replace ALooper_pollAll with ALooper_pollOnce. ALooper_pollAll can't be called safely and is being removed from the NDK. Replace with ALooper_pollOnce. --- native-activity/app/src/main/cpp/main.cpp | 35 ++++++++++++----------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/native-activity/app/src/main/cpp/main.cpp b/native-activity/app/src/main/cpp/main.cpp index bec031b27..3c03a850d 100644 --- a/native-activity/app/src/main/cpp/main.cpp +++ b/native-activity/app/src/main/cpp/main.cpp @@ -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(&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)