From ece52f26503987bbfd2ded8c73ffde05c457d035 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 | 26 ++++++++++------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/native-activity/app/src/main/cpp/main.cpp b/native-activity/app/src/main/cpp/main.cpp index bec031b27..bea2c2de0 100644 --- a/native-activity/app/src/main/cpp/main.cpp +++ b/native-activity/app/src/main/cpp/main.cpp @@ -404,25 +404,21 @@ 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); - } + android_poll_source* source = nullptr; + auto result = ALooper_pollOnce(-1, nullptr, nullptr, + reinterpret_cast(&source)); + if (result == ALOOPER_POLL_ERROR) { + fatal("ALooper_pollOnce returned an error"); + } - // Check if we are exiting. - if (state->destroyRequested != 0) { - engine_term_display(&engine); - return; - } + if (source != nullptr) { + source->process(state, source); } } + + engine_term_display(&engine); } // END_INCLUDE(all)