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

SfxMan class in endless tunnel doesn't ever initialize `mInitOk` if there is an error during initialization #960

Open Mis012 opened 1 year ago

Mis012 commented 1 year ago

It seems that mInitOk is supposed to only be set to true when initialization is successful, however it is never initialized otherwise so when initialization is not successful, it's value is undefined. In practice, this causes a random crash when the memory where it's stored happens to contain something other than 0.

The following should probably fix it, but feel free to implement a different fix. Considering the triviality of the following change, it's clearly exempted from copyright so I shouldn't need to deal with any CLA should you wish to use this fix.

diff --git a/endless-tunnel/app/src/main/cpp/sfxman.hpp b/endless-tunnel/app/src/main/cpp/sfxman.hpp
index bc72a90..b604553 100644
--- a/endless-tunnel/app/src/main/cpp/sfxman.hpp
+++ b/endless-tunnel/app/src/main/cpp/sfxman.hpp
@@ -30,7 +30,7 @@
  * to a more complex game. */
 class SfxMan {
  private:
-  bool mInitOk;
+  bool mInitOk = 0;
   SLAndroidSimpleBufferQueueItf mPlayerBufferQueue;

  public: