Skip to content

Commit

Permalink
Fix potential ANR issues caused by unsafe calls to the ALooper_pollAl…
Browse files Browse the repository at this point in the history
…l interface.
  • Loading branch information
bofeng-song committed Dec 11, 2024
1 parent 970e91c commit e68b499
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions native/cocos/platform/android/AndroidPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -849,15 +849,24 @@ void AndroidPlatform::exit() {
int32_t AndroidPlatform::loop() {
IXRInterface *xr = CC_GET_XR_INTERFACE();
while (true) {
int events;
struct android_poll_source *source;

// suspend thread while _loopTimeOut set to -1
while ((ALooper_pollAll(_loopTimeOut, nullptr, &events,
reinterpret_cast<void **>(&source))) >= 0) {
// process event
if (source != nullptr) {
source->process(_app, source);
while (true) {
int pollResult = ALooper_pollOnce(_loopTimeOut, nullptr, nullptr,
reinterpret_cast<void **>(&source));

// Process events if any
if (pollResult == ALOOPER_POLL_ERROR) {
CC_LOG_ERROR("ALooper_pollOnce returned and error");
break;
} else {

Check failure on line 863 in native/cocos/platform/android/AndroidPlatform.cpp

View workflow job for this annotation

GitHub Actions / ClangTidy Android

do not use 'else' after 'break' (readability-else-after-return)
if (source != nullptr) {
source->process(_app, source);
}
if (pollResult == ALOOPER_POLL_TIMEOUT) {
break;
}
}

// Exit the game loop when the Activity is destroyed
Expand Down

0 comments on commit e68b499

Please sign in to comment.