fxlab: On Moto G6, headphone unplug, then calling `enableEffectNative` crashes
- Dominant language
- C++
- Stars
- 4.1k
- Forks
- 639
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 8
Description
Android version(s): 9
Android device(s): moto g6
Oboe version: https://github.com/google/oboe/tree/3aad74264222f07b48d02cfc0afe53fd91786c99
App name used for testing: lib on my app
**Short description**
On Moto G6, headphone unplug, then trying to enable/disable a sound using `enableEffectNative` crashes
**Steps to reproduce**
This is hard to reproduce, does not always occur, but on moto g6, if we play some effects, then take off the headphone, then try to enable/disable some effect through `enableEffectNative`, app crashes.
I traced the problem back to `void enableEffectAt(size_t index, bool enable) {` from https://github.com/google/oboe/blob/40283a78b98aefafd340b0d75a313efa61d8c8cd/apps/fxlab/app/src/main/cpp/FunctionList.h#L70
I rewrote the constructor and destructor for `FunctionList` and saw that on headphone unplug, `FunctionList` is being recreated. However, no effects are readded! So, when we try to call `enableEffectNative`, it uses an `std::visit` that visits the `functionList` and tries to enable something on an index that does not exist.
Changing the function to
```
void enableEffectAt(size_t index, bool enable) {
if (!functionList.empty())
functionList[index].second = enable;
else
__android_log_print(ANDROID_LOG_DEBUG, "DRUMTHUMPER", "%s", "NO ELEMENT FOUND, SOMETHING IS WRONG");
}
```
fixes the problem and I can still play sounds, but it's not the right solution and probably some things are missing. A simple `.at(index)` would be better so I can check for an Exception but anyways still something should be there. I'm just not familiar enough with the library and I don't know where the `FunctionList` is being destructed and recreated. Probably on the thread that serves as a watchdog for headphone unplug, but I'm not familiar with the entire library.
Maybe all the container acesses on the library should be checked so we have clearer errors? And maybe we should readd the `functionList` upon `FunctionList` recreation?
**Expected behavior**
Nothing happens on headphone unplug. Ok, the entire thing can be recreated but it should readd the `functionList`
Contributor guide
Assessment
This issue has not been assessed yet.