I’m developing a react native library for my upcoming android app using fmod. So far I’ve been testing it only with files coming from the android_asset folder (
file:///android_asset/sound.ogg
) and everything worked decently. Today I started integrating firebase to download some sounds from my cdn and store them in the app’s document folder at runtime
(file:///data/user/0/com.dominickv.ambientify/files/sounds/downloaded/sound.ogg)
… The first time I load the sound everything works, but when I reload the sound after it ends (I do this to prevent deleting the channel since I need to always reuse at least 15 channels, for functionality reasons) the app crashes without giving me any hints as to what went wrong. It only tells me something went wrong and I should contact support…
The repository for my code is public if you want to look at the code
(disclaimer: it’s ugly and I’m not a professional c++ programmer, the link points to the line where the error shows up). This is the logs of the crash:
Type Time PID Tag Message
14:05:09.416 3618 AmbientifySoundEngine Loading channel 0
14:05:09.416 3618 fmod SystemI::createSoundInternal : Create name='file:///data/user/0/com.dominickv.ambientify/files/sounds/downloaded/Crow_01.ogg', mode=0x00000082
14:05:09.417 3618 fmod SystemI::createSoundInternal : Stream: name='(null)', format=2, channels=2, frequency=44100, lengthbytes=25357, lengthpcm=132936, pcmblocksize=0, loopstart=0, loopend=0, mode=0x00000000, channelmask=0x00000000, channelorder=0, peakvolume=0.000000.
14:05:09.420 3618 fmod Thread::initThread : Init FMOD file thread. Affinity: 0x4000000000000003, Priority: 0xFFFF7FFC, Stack Size: 65536, Semaphore: No, Sleep Time: 10, Looping: Yes.
14:05:09.421 3618 AmbientifySoundEngine Preparing channel 0
14:05:09.466 3618 ReactNativeJS 'Rendered channel: ', 0
14:05:10.836 3618 ReactNativeJS Preview soundInstance unloaded succesfully.
14:05:15.305 3618 ReactNativeJS 'Rendered channel: ', 0
14:05:16.245 3618 unknown:ReactModalHost Creating new dialog from context: com.dominickv.ambientify.MainActivity@e4a1084@239734916
14:05:16.269 1460 SurfaceFlinger duplicate layer name: changing com.dominickv.ambientify/com.dominickv.ambientify.MainActivity to com.dominickv.ambientify/com.dominickv.ambientify.MainActivity#1
14:05:16.280 1446 gralloc_ranchu gralloc_alloc: Creating ashmem region of size 10108928
14:05:16.287 1446 chatty uid=1000(system) HwBinder:1446_2 identical 1 line
14:05:16.299 1446 gralloc_ranchu gralloc_alloc: Creating ashmem region of size 10108928
14:05:16.311 3618 unknown:ReactModalHost Updating existing dialog with context: com.dominickv.ambientify.MainActivity@e4a1084@239734916
14:05:16.325 3618 EGL_emulation eglMakeCurrent: 0xdb6055c0: ver 3 1 (tinfo 0xc8bd2860)
14:05:16.347 3618 chatty uid=10059(com.dominickv.ambientify) RenderThread identical 2 lines
14:05:16.352 3618 EGL_emulation eglMakeCurrent: 0xdb6055c0: ver 3 1 (tinfo 0xc8bd2860)
14:05:16.389 3618 ReactNativeJS 'Rendered channel: ', 0
14:05:17.251 3618 EGL_emulation eglMakeCurrent: 0xdb6055c0: ver 3 1 (tinfo 0xc8bd2860)
14:05:17.873 3618 ReactNativeJS 'Rendered channel: ', 0
14:05:18.337 3618 EGL_emulation eglMakeCurrent: 0xdb6055c0: ver 3 1 (tinfo 0xc8bd2860)
14:05:18.603 1711 zygote Background concurrent copying GC freed 65221(3MB) AllocSpace objects, 21(868KB) LOS objects, 42% free, 6MB/10MB, paused 701us total 110.164ms
14:05:18.622 3618 PlayerBase::~PlayerBase()
14:05:20.404 3618 ReactNativeJS 'Rendered channel: ', 0
14:05:20.734 3618 EGL_emulation eglMakeCurrent: 0xdb6055c0: ver 3 1 (tinfo 0xc8bd2860)
14:05:23.392 3618 AmbientifySoundEngine _ch ended with id: 0
14:05:23.392 3618 AmbientifySoundEngine Loading channel 0
14:05:23.392 3618 fmod SystemI::createSoundInternal : Create name='file:///data/user/0/com.dominickv.ambientify/files/sounds/downloaded/Crow_01.ogg', mode=0x00000081
14:05:23.392 3618 fmod FMOD_JNI_GetEnv : Native threads must be attached to the Java virtual machine, please call JavaVM::AttachCurrentThread before invocation.
14:05:23.392 3618 AmbientifySoundEngine EngineChannel.cpp(41): FMOD error 28 - An error occurred that wasn't supposed to. Contact support.
14:05:23.395 3618 libc /buildbot/src/android/ndk-release-r21/external/libcxx/../../external/libcxxabi/src/abort_message.cpp:72: abort_message: assertion "terminating with uncaught exception of type ambientify::commons::ASoundEngineException: EngineChannel.cpp(line 41): FMOD error 28 - An error occurred that wasn't supposed to. Contact support." failed
14:05:23.396 3618 libc Fatal signal 6 (SIGABRT), code -6 in tid 3718 (mqt_js), pid 3618 (ickv.ambientify)
14:05:23.459 3759 crash_dump32 obtaining output fd from tombstoned, type: kDebuggerdTombstone
14:05:23.464 1593 /system/bin/tombstoned received crash request for pid 3618
14:05:23.466 3759 crash_dump32 performing dump of process 3618 (target tid = 3718)
14:05:23.466 3759 DEBUG *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
14:05:23.466 3759 DEBUG Build fingerprint: 'Android/sdk_phone_x86/generic_x86:8.1.0/OSM1.180201.023/4931629:userdebug/test-keys'
14:05:23.466 3759 DEBUG Revision: '0'
14:05:23.466 3759 DEBUG ABI: 'x86'
14:05:23.467 3759 DEBUG pid: 3618, tid: 3718, name: mqt_js >>> com.dominickv.ambientify <<<
14:05:23.467 3759 DEBUG signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
14:05:23.468 3759 DEBUG Abort message: '/buildbot/src/android/ndk-release-r21/external/libcxx/../../external/libcxxabi/src/abort_message.cpp:72: abort_message: assertion "terminating with uncaught exception of type ambientify::commons::ASoundEngineException: EngineChannel.cpp(line 41): FMOD error 28 - An error occurred that wasn't supposed to. Contact support." failed'
14:05:23.468 3759 DEBUG eax 00000000 ebx 00000e22 ecx 00000e86 edx 00000006
14:05:23.468 3759 DEBUG esi e4de6638 edi 00000e22
14:05:23.468 3759 DEBUG xcs 00000023 xds 0000002b xes 0000002b xfs 0000006b xss 0000002b
14:05:23.468 3759 DEBUG eip e7d4dae5 ebp 00000e86 esp b6c01b60 flags 00000286
14:05:23.477 3759 DEBUG
backtrace:
14:05:23.477 3759 DEBUG #00 pc 00000ae5 [vdso:e7d4d000] (__kernel_vsyscall+5)
14:05:23.477 3759 DEBUG #01 pc 0001edf8 /system/lib/libc.so (syscall+40)
14:05:23.477 3759 DEBUG #02 pc 0001f073 /system/lib/libc.so (abort+115)
14:05:23.477 3759 DEBUG #03 pc 0001f528 /system/lib/libc.so (__assert2+56)
14:05:23.477 3759 DEBUG #04 pc 00099d94 /data/app/com.dominickv.ambientify-2cZgIeXEMj1F-WfyMHA-JQ==/lib/x86/libc++_shared.so
14:05:23.477 3759 DEBUG #05 pc 00099fee /data/app/com.dominickv.ambientify-2cZgIeXEMj1F-WfyMHA-JQ==/lib/x86/libc++_shared.so
14:05:23.477 3759 DEBUG #06 pc 000b11a9 /data/app/com.dominickv.ambientify-2cZgIeXEMj1F-WfyMHA-JQ==/lib/x86/libc++_shared.so
14:05:23.477 3759 DEBUG #07 pc 000b05ae /data/app/com.dominickv.ambientify-2cZgIeXEMj1F-WfyMHA-JQ==/lib/x86/libc++_shared.so
14:05:23.477 3759 DEBUG #08 pc 000b0503 /data/app/com.dominickv.ambientify-2cZgIeXEMj1F-WfyMHA-JQ==/lib/x86/libc++_shared.so (__cxa_throw+115)
14:05:23.477 3759 DEBUG #09 pc 00044e80 /data/app/com.dominickv.ambientify-2cZgIeXEMj1F-WfyMHA-JQ==/lib/x86/libambientifySoundEngine.so (ERRCHECK_fn(FMOD_RESULT, char const*, int)+960)
14:05:23.478 3759 DEBUG #10 pc 0008c489 /data/app/com.dominickv.ambientify-2cZgIeXEMj1F-WfyMHA-JQ==/lib/x86/libambientifySoundEngine.so (ambientify::EngineChannel::load(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>> const*)+777)
14:05:23.478 3759 DEBUG #11 pc 0008d670 /data/app/com.dominickv.ambientify-2cZgIeXEMj1F-WfyMHA-JQ==/lib/x86/libambientifySoundEngine.so (ambientify::EngineChannel::load(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>> const*, bool)+80)
14:05:23.478 3759 DEBUG #12 pc 0008fdb5 /data/app/com.dominickv.ambientify-2cZgIeXEMj1F-WfyMHA-JQ==/lib/x86/libambientifySoundEngine.so (ambientify::EngineChannel::onChannelEndCallback()+133)
14:05:23.478 3759 DEBUG #13 pc 0007d1bf /data/app/com.dominickv.ambientify-2cZgIeXEMj1F-WfyMHA-JQ==/lib/x86/libambientifySoundEngine.so (ambientify::SoundEngine::channelCallback(FMOD_CHANNELCONTROL*, FMOD_CHANNELCONTROL_TYPE, FMOD_CHANNELCONTROL_CALLBACK_TYPE, void*, void*)+559)
14:05:23.478 3759 DEBUG #14 pc 00089ec0 /data/app/com.dominickv.ambientify-2cZgIeXEMj1F-WfyMHA-JQ==/lib/x86/libfmodL.so (offset 0x7e000)
14:05:23.478 3759 DEBUG #15 pc 0008fc74 /data/app/com.dominickv.ambientify-2cZgIeXEMj1F-WfyMHA-JQ==/lib/x86/libfmodL.so (offset 0x7e000)
14:05:23.478 3759 DEBUG #16 pc 000c4709 /data/app/com.dominickv.ambientify-2cZgIeXEMj1F-WfyMHA-JQ==/lib/x86/libfmodL.so (offset 0x7e000)
14:05:23.478 3759 DEBUG #17 pc 000c4047 /data/app/com.dominickv.ambientify-2cZgIeXEMj1F-WfyMHA-JQ==/lib/x86/libfmodL.so (offset 0x7e000)
14:05:23.478 3759 DEBUG #18 pc 000aac9e /data/app/com.dominickv.ambientify-2cZgIeXEMj1F-WfyMHA-JQ==/lib/x86/libfmodL.so (offset 0x7e000)
14:05:23.478 3759 DEBUG #19 pc 00159e0f /data/app/com.dominickv.ambientify-2cZgIeXEMj1F-WfyMHA-JQ==/lib/x86/libfmodL.so (offset 0x7e000) (FMOD::System::update()+71)
14:05:23.478 3759 DEBUG #20 pc 0007dde1 /data/app/com.dominickv.ambientify-2cZgIeXEMj1F-WfyMHA-JQ==/lib/x86/libambientifySoundEngine.so (ambientify::SoundEngine::update()+97)
14:05:23.478 3759 DEBUG #21 pc 000856db /data/app/com.dominickv.ambientify-2cZgIeXEMj1F-WfyMHA-JQ==/lib/x86/libambientifySoundEngine.so
14:05:23.479 3759 DEBUG #22 pc 0008557c /data/app/com.dominickv.ambientify-2cZgIeXEMj1F-WfyMHA-JQ==/lib/x86/libambientifySoundEngine.so
14:05:23.479 3759 DEBUG #23 pc 00084bbf /data/app/com.dominickv.ambientify-2cZgIeXEMj1F-WfyMHA-JQ==/lib/x86/libambientifySoundEngine.so (_ZNSt6__ndk114__thread_proxyINS_5tupleIJNS_10unique_ptrINS_15__thread_structENS_14default_deleteIS3_EEEEMN10ambientify11SoundEngineEFvvEPS8_EEEEEPvSD_+207)
14:05:23.479 3759 DEBUG #24 pc 00071445 /system/lib/libc.so (__pthread_start(void*)+53)
14:05:23.479 3759 DEBUG #25 pc 000205db /system/lib/libc.so (__start_thread+75)
14:05:23.479 3759 DEBUG #26 pc 0001ec16 /system/lib/libc.so (__bionic_clone+70)
14:05:23.951 1593 /system/bin/tombstoned Tombstone written to: /data/tombstones/tombstone_00
14:05:23.954 1711 BootReceiver Copying /data/tombstones/tombstone_00 to DropBox (SYSTEM_TOMBSTONE)
14:05:23.958 1711 ActivityManager Force finishing activity com.dominickv.ambientify/.MainActivity
14:05:23.966 1447 hwcomposer hw_composer sent 42 syncs in 103s
14:05:23.968 1711 ActivityManager Showing crash dialog for package com.dominickv.ambientify u0
14:05:24.170 1446 gralloc_ranchu gralloc_alloc: Creating ashmem region of size 2801664
14:05:24.250 1711 zygote android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
14:05:24.250 1711 OpenGLRenderer Initialized EGL, version 1.4
14:05:24.250 1711 OpenGLRenderer Swap behavior 1
14:05:24.250 1711 OpenGLRenderer Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
14:05:24.250 1711 OpenGLRenderer Swap behavior 0
14:05:24.270 1446 gralloc_ranchu gralloc_alloc: Creating ashmem region of size 2801664
14:05:24.270 1711 EGL_emulation eglCreateContext: 0xd8ce1580: maj 3 min 1 rcv 4
14:05:24.320 1446 gralloc_ranchu gralloc_alloc: Creating ashmem region of size 2801664
14:05:24.330 1711 EGL_emulation eglMakeCurrent: 0xd8ce1580: ver 3 1 (tinfo 0xc6f7a170)
14:05:24.350 1711 eglCodecCommon glUtilsParamSize: unknow param 0x000082da
14:05:24.350 1711 eglCodecCommon glUtilsParamSize: unknow param 0x000082da
14:05:24.370 1711 ConnectivityService ConnectivityService NetworkRequestInfo binderDied(NetworkRequest [ TRACK_DEFAULT id=12, [ Capabilities: INTERNET&NOT_RESTRICTED&TRUSTED&NOT_VPN] ], android.os.BinderProxy@ccf4d74)
14:05:24.380 1711 ConnectivityService releasing NetworkRequest [ TRACK_DEFAULT id=12, [ Capabilities: INTERNET&NOT_RESTRICTED&TRUSTED&NOT_VPN] ] (release request)
14:05:24.410 1711 WindowManager WIN DEATH: Window{2c37367 u0 com.dominickv.ambientify/com.dominickv.ambientify.MainActivity}
14:05:24.440 1711 ActivityManager Process com.dominickv.ambientify (pid 3618) has died: fore TOP
14:05:24.440 1711 ActivityManager Scheduling restart of crashed service com.dominickv.ambientify/app.notifee.core.ForegroundService in 1000ms
14:05:24.450 1711 zygote kill(-3618, 9) failed: No such process
14:05:24.450 1711 WindowManager WIN DEATH: Window{50c1323 u0 com.dominickv.ambientify/com.dominickv.ambientify.MainActivity}
14:05:24.500 1711 ConnectivityService ConnectivityService NetworkRequestInfo binderDied(NetworkRequest [ TRACK_DEFAULT id=13, [ Capabilities: INTERNET&NOT_RESTRICTED&TRUSTED&NOT_VPN] ], android.os.BinderProxy@4e2a312)
14:05:24.500 1711 ConnectivityService releasing NetworkRequest [ TRACK_DEFAULT id=13, [ Capabilities: INTERNET&NOT_RESTRICTED&TRUSTED&NOT_VPN] ] (release request)
14:05:24.600 1576 Zygote Process 3618 exited due to signal (6)
14:05:24.850 1711 ActivityManager setHasOverlayUi called on unknown pid: 3618
14:05:24.860 1711 zygote kill(-3618, 9) failed: No such process
14:05:24.860 1711 zygote Successfully killed process cgroup uid 10059 pid 3618 in 41ms
14:05:24.960 1711 EGL_emulation eglMakeCurrent: 0xd8ce1580: ver 3 1 (tinfo 0xc6f7a170)
14:05:24.120 1446 gralloc_ranchu gralloc_alloc: Creating ashmem region of size 10108928
14:05:24.125 1446 chatty uid=1000(system) HwBinder:1446_2 identical 1 line
14:05:24.128 1446 gralloc_ranchu gralloc_alloc: Creating ashmem region of size 10108928
14:05:24.187 2355 EGL_emulation eglMakeCurrent: 0xdb6042a0: ver 3 1 (tinfo 0xdb603550)
14:05:24.215 1711 Looper Dispatch took 162ms on android.ui, h=Handler (android.view.Choreographer$FrameHandler) {41b1ae3} cb=android.view.Choreographer$FrameDisplayEventReceiver@4dcce0 msg=0
14:05:24.227 1856 EGL_emulation eglMakeCurrent: 0xca16e9e0: ver 3 1 (tinfo 0xca1fb890)
14:05:24.468 1856 chatty uid=10024(com.android.systemui) RenderThread identical 21 lines
14:05:24.479 1856 EGL_emulation eglMakeCurrent: 0xca16e9e0: ver 3 1 (tinfo 0xca1fb890)
14:05:24.652 2355 OpenGLRenderer Incorrectly called buildLayer on View: ShortcutAndWidgetContainer, destroying layer...
14:05:27.900 1711 TaskPersister File error accessing recents directory (directory doesn't exist?).
14:05:27.121 1439 audio_hw_generic Not supplying enough data to HAL, expected position 10938437 , only wrote 8945280
I really, really don’t know why it’s crashing, I don’t expect anyone to read the code and understand everything but after many trials I’m pretty sure the only variable is the sound location. The same sound, same code, same emulator, same android version, same build of everything, it only crashes when trying to reload the same sound coming from the downloaded folder instead of the assets one.
Any help would be much appreciated… I was getting so close to shipping my app…
Tombstone attached below
tombstone_00.txt (487.1 KB)
Nothing obvious is jumping out at me from the code you have shared. I have a few questions:
What version of FMOD are you using?
Do non-streaming sounds have the same problem?
Do both looping and non-looping sounds have this same problem?
I just downloaded the latest 0x00020209 2.02
Yes, it doesn’t matter the mode, it happens with compressed, sample and stream.
If by looping you mean the loop mode then if it is set to FMOD_LOOP_NORMAL it doesn’t crash since it never has to reload the sound.
Thank you for the additional information. I have not been able to reproduce this issue with sounds loaded from the Downloads folder.
FMOD_ERR_INTERNAL
is usually accompanied by a log. To see this log however you need to use the logging libs (libfmodL.so instead of libfmod.so) and call Debug_Initialize(FMOD_DEBUG_LEVEL_LOG)
at the start of your application.
Can you please try getting that setup and share the log after this crash?
Just to be sure, what i meant by “downloaded” folder is this folder I create after downloading a sound:
file:///data/user/0/com.my.app/files/sounds/downloaded/sound.ogg
, not the Downloads folder in the storage.
attached the logs from fmod copied from logcat. If you meant that a log file should’ve been written I don’t know where it is and there is no mention of it… I tried using FMOD_DEBUG_MODE_FILE, but I couldn’t figure out what to put in the filename argument (I couldn’t find any additional info on the docs about it and I tried both a path on my machine and on the emulator and crashed with “file not found”)
I called
result = FMOD::Debug_Initialize(
FMOD_DEBUG_LEVEL_LOG |
FMOD_DEBUG_TYPE_MEMORY |
FMOD_DEBUG_TYPE_FILE |
FMOD_DEBUG_TYPE_CODEC |
FMOD_DEBUG_TYPE_TRACE |
FMOD_DEBUG_DISPLAY_TIMESTAMPS |
FMOD_DEBUG_DISPLAY_LINENUMBERS |
FMOD_DEBUG_DISPLAY_THREAD ,FMOD_DEBUG_MODE_TTY, 0, 0);
fmodlog.txt (259.8 KB)
Thank you for sending over the log, I can see the accompanying message for this error is:
TID 3277 : 178910 ms +1606 : [LOG] SystemI::createSoundInternal : Create name='file:///data/user/0/com.dominickv.ambientify/files/sounds/downloaded/animals%3Ebirds%3ECrow_01.ogg', mode=0x00000081
TID 3277 : 178910 ms +0 : [ERR] FMOD_JNI_GetEnv : Native threads must be attached to the Java virtual machine, please call JavaVM::AttachCurrentThread before invocation.
Note the thread id is different to the one previously used for createSound:
TID 3232 : 166871 ms +0 : [LOG] SystemI::createSoundInternal : Stream: name='(null)', format=2, channels=2, frequency=44100, lengthbytes=25357, lengthpcm=132936, pcmblocksize=0, loopstart=0, loopend=0, mode=0x00000000, channelmask=0x00000000, channelorder=0, peakvolume=0.000000.
I see you are loading sounds in a promise, which internally is creating a new thread and means you would need to call JavaVM::AttachCurrentThread
. It should just be a matter of calling AttachCurrentThread
inside your “createChannelAsync” lambda and passing in the java vm your are holding in cpp-adapter.cpp.
Oh, wow, thank you so so so much for your help. It worked — technically, I had to call AttachCurrentThread in my update method, which is also on another thread, not on my async lambdas. But thank you again, and I apologize for my bad code.
Although I still have no idea why this only happens with files outside the android assets folder since, as I said, everything worked with those, and I never had this happen.
Thank you for confirming that is working now. I am seeing a difference between the implementations when loading from “file:///android_asset/” and “file:///” by itself that might explain why this is happening. This is probably a bug- I have passed this onto the dev team to investigate in more detail. Thank you for bringing this to our attention.
EDIT: After discussion with the dev team they have pointed out that this is expected behaviour, and it is a requirement that all calls into FMOD from a native thread need to be attached using JavaVM::AttachCurrentThread
.