android / ndk-samples

Android NDK samples with Android Studio
http://developer.android.com/ndk
Apache License 2.0
10.06k stars 4.18k forks source link

Replace `ALooper_pollAll` with `ALooper_pollOnce`. #1002

Closed DanAlbert closed 5 months ago

DanAlbert commented 5 months ago

The pollAll API was removed because it can't be used safely. The recommendation is to replace existing calls to pollAll with pollOnce with an explicit loop.

There are quite a few other samples that are doing this. Fixing one to start so I can check with someone that understands the pollAll bug so I don't accidentally copy the same bug, then I'll fix the others.

https://github.com/android/ndk-samples/issues/999

DanAlbert commented 5 months ago

@jreck says this isn't actually a good fix. The problem is present when calling pollOnce in a loop as I have here as well. The nuance is that this sample doesn't have the bug at all, because the problem only happens when ALooper_wake is used, and this sample doesn't do that. OTOH, this sample doesn't do that mainly because it's trivial. Anything built with this sample as its base likely would.

The better fix is to migrate to AChoreographer. I'll close this and upload a new PR that does that.