android / android/ndk-samples

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

Open
#960 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
10.5k
Forks
4.3k
PR merge metrics
No merged PRs in 30d

Description

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
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:
```

Contributor guide

Open the contributing guide

Research direction

Open endless-tunnel/app/src/main/cpp/sfxman.hpp and inspect how SfxMan initializes mInitOk when initialization reports an error. Confirm the endless tunnel sample no longer uses an undefined value for that state and verify that the reported random crash condition is removed.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, cpp
Domain
game-dev, mobile-dev
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.