Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: crash on deinit() #68

Closed
alnitak opened this issue Mar 23, 2024 · 1 comment
Closed

bug: crash on deinit() #68

alnitak opened this issue Mar 23, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@alnitak
Copy link
Owner

alnitak commented Mar 23, 2024

Description

Calling init() and immediately after deinit() causes a random crash on some Android versions.

Steps To Reproduce

  1. Run something similar to this:
for (var i = 0; i < 100; i++) {
  await SoLoud.instance.init();
  SoLoud.instance.deinit();
}
  1. expect a crash

Additional Context

Test passed on:
emulator - Android 14 API 34
emulator - Android 13 API 33
emulator - Android 12L API 32
emulator - Android 12 API 31
emulator - Android 11 API 30
Samsung Galaxy Note20 Ultra - Android 13 API 33
Samsung Galaxy Note10+ - Android 12 API 31,32
Samsung Galaxy S9+ - Android 10 API 29

Test NOT passed on:
emulator - Android 10 API 29
Xiaomi Mi Max 3 - Android 10 API 29
Huawei P smart Z - Android 10 API 29
Xiaomi Mi 6 - Android 9 SDK 28

Here the error log

I/flutter (10278): [FINEST] flutter_soloud.SoLoud: init() called
I/flutter (10278): [FINEST] flutter_soloud.SoLoudLoader: initialize() called
I/flutter (10278): [FINE] flutter_soloud.SoLoudLoader: Loader has already been initialized. Not
I/flutter (10278): initializing again.
I/flutter (10278): [FINEST] flutter_soloud.SoLoud: _initEngine() called
D/miniaudio(10278): DEBUG: WASAPI backend is disabled.
D/miniaudio(10278): DEBUG: DirectSound backend is disabled.
D/miniaudio(10278): DEBUG: WinMM backend is disabled.
D/miniaudio(10278): DEBUG: Core Audio backend is disabled.
D/miniaudio(10278): DEBUG: sndio backend is disabled.
D/miniaudio(10278): DEBUG: audio(4) backend is disabled.
D/miniaudio(10278): DEBUG: OSS backend is disabled.
D/miniaudio(10278): DEBUG: PulseAudio backend is disabled.
D/miniaudio(10278): DEBUG: ALSA backend is disabled.
D/miniaudio(10278): DEBUG: JACK backend is disabled.
D/miniaudio(10278): DEBUG: Attempting to initialize AAudio backend...
D/miniaudio(10278): DEBUG: Loading library: libaaudio.so
D/miniaudio(10278): DEBUG: Loading symbol: AAudio_createStreamBuilder
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStreamBuilder_delete
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStreamBuilder_setDeviceId
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStreamBuilder_setDirection
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStreamBuilder_setSharingMode
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStreamBuilder_setFormat
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStreamBuilder_setChannelCount
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStreamBuilder_setSampleRate
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStreamBuilder_setBufferCapacityInFrames
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStreamBuilder_setFramesPerDataCallback
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStreamBuilder_setDataCallback
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStreamBuilder_setErrorCallback
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStreamBuilder_setPerformanceMode
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStreamBuilder_setUsage
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStreamBuilder_setContentType
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStreamBuilder_setInputPreset
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStreamBuilder_setAllowedCapturePolicy
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStreamBuilder_openStream
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStream_close
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStream_getState
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStream_waitForStateChange
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStream_getFormat
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStream_getChannelCount
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStream_getSampleRate
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStream_getBufferCapacityInFrames
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStream_getFramesPerDataCallback
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStream_getFramesPerBurst
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStream_requestStart
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStream_requestStop
D/miniaudio(10278): DEBUG: System Architecture:
D/miniaudio(10278): DEBUG:   Endian: LE
D/miniaudio(10278): DEBUG:   SSE2:   NO
D/miniaudio(10278): DEBUG:   AVX2:   NO
D/miniaudio(10278): DEBUG:   NEON:   YES
I/AAudio  (10278): AAudioStreamBuilder_openStream() called ----------------------------------------
I/AudioStreamBuilder(10278): rate   =  44100, channels  = 2, format   = 5, sharing = SH, dir = OUTPUT
I/AudioStreamBuilder(10278): device =      0, sessionId = -1, perfMode = 12, callback: ON with frames = 2048
I/AudioStreamBuilder(10278): usage  =      0, contentType = 0, inputPreset = 0, allowedCapturePolicy = 0
D/        (10278): PlayerBase::PlayerBase()
D/AudioStreamTrack(10278): open(), request notificationFrames = 2048, frameCount = 6144
W/AudioTrack(10278): createTrack_l(111): AUDIO_OUTPUT_FLAG_FAST denied by server; frameCount 6144 -> 6144
W/AudioStreamTrack(10278): open() flags changed from 0x00000104 to 0x00000000
W/AudioStreamTrack(10278): open() perfMode changed from 12 to 10
I/AAudio  (10278): AAudioStreamBuilder_openStream() returns 0 = AAUDIO_OK for s#9 ----------------
D/miniaudio(10278): INFO: [AAudio]
D/miniaudio(10278): INFO:    (Playback)
D/miniaudio(10278): INFO:     Format:      32-bit IEEE Floating Point -> 32-bit IEEE Floating Point
D/miniaudio(10278): INFO:     Channels:    2 -> 2
D/miniaudio(10278): INFO:     Sample Rate: 44100 -> 44100
D/miniaudio(10278): INFO:     Buffer Size: 2048*3 (6144)
D/miniaudio(10278): INFO:     Conversion:
D/miniaudio(10278): INFO:       Pre Format Conversion:  NO
D/miniaudio(10278): INFO:       Post Format Conversion: NO
D/miniaudio(10278): INFO:       Channel Routing:        NO
D/miniaudio(10278): INFO:       Resampling:             NO
D/miniaudio(10278): INFO:       Passthrough:            YES
D/miniaudio(10278): INFO:       Channel Map In:         {CHANNEL_FRONT_LEFT CHANNEL_FRONT_RIGHT}
D/miniaudio(10278): INFO:       Channel Map Out:        {CHANNEL_FRONT_LEFT CHANNEL_FRONT_RIGHT}
D/AAudio  (10278): AAudioStream_requestStart(s#9) called --------------
D/        (10278): PlayerBase::start() from IPlayer
D/AAudio  (10278): AAudioStream_requestStart(s#9) returned 0 ---------
D/AudioStreamLegacy(10278): onAudioDeviceUpdate() devId 3 => 3
I/flutter (10278): [FINEST] flutter_soloud.SoLoud: main isolate received: {event:
I/flutter (10278): MessageEvents.initEngine, args: (), return: PlayerErrors.noError (No error)}
I/flutter (10278): [FINEST] flutter_soloud.SoLoud: _startLoop() called
I/flutter (10278): [FINEST] flutter_soloud.SoLoud: main isolate received: {event:
I/flutter (10278): MessageEvents.startLoop, args: (), return: ()}

/************* deinit ***************/
I/flutter (10278): [FINEST] flutter_soloud.SoLoud: deinit() called
D/AAudio  (10278): AAudioStream_close(s#9) called ---------------
F/libc    (10278): /home/deimos/FLUTTER/libs/flutter_soloud/src/soloud/src/backend/miniaudio/miniaudio.h:18849: void ma_device__read_frames_from_client(ma_device *, ma_uint32, void *): assertion "frameCount > 0" failed
F/libc    (10278): Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 10346 (AudioTrack), pid 10278 (.soloud.example)
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'Xiaomi/nitrogen/nitrogen:10/QKQ1.190910.002/V12.0.1.0.QEDMIXM:user/release-keys'
Revision: '0'
ABI: 'arm64'
Timestamp: 2024-03-24 10:35:31+0100
pid: 10278, tid: 10346, name: AudioTrack  >>> flutter.soloud.example <<<
uid: 10978
signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr --------
Abort message: '/home/deimos/FLUTTER/libs/flutter_soloud/src/soloud/src/backend/miniaudio/miniaudio.h:18849: void ma_device__read_frames_from_client(ma_device *, ma_uint32, void *): assertion "frameCount > 0" failed'
    x0  0000000000000000  x1  000000000000286a  x2  0000000000000006  x3  0000007043a3d760
    x4  0000000000000000  x5  0000000000000000  x6  0000000000000000  x7  0000000000000040
    x8  00000000000000f0  x9  93f4f948f118562d  x10 0000000000000001  x11 0000000000000000
    x12 fffffff0fffffbdf  x13 0000000065fff3e3  x14 001f80693de3fd37  x15 00006a70bd14a6f1
    x16 000000714e6b88c0  x17 000000714e694900  x18 00000070433a8000  x19 0000000000002826
    x20 000000000000286a  x21 00000000ffffffff  x22 0000007044c95310  x23 0100804010040101
    x24 00000070c3328520  x25 00000070c33284a0  x26 00000070c3328748  x27 0000000000000421
    x28 0000000000000009  x29 0000007043a3d800
    sp  0000007043a3d740  lr  000000714e6460c4  pc  000000714e6460f0
backtrace:
      #00 pc 00000000000830f0  /apex/com.android.runtime/lib64/bionic/libc.so (abort+160) (BuildId: 328a3518945f3e056fc055f1eea1cc35)
      #01 pc 000000000008348c  /apex/com.android.runtime/lib64/bionic/libc.so (__assert2+36) (BuildId: 328a3518945f3e056fc055f1eea1cc35)
      #02 pc 0000000000112fd8  /data/app/flutter.soloud.example-k-p97bVufhg8O0OMd1yCmA==/lib/arm64/libflutter_soloud_plugin.so (BuildId: 9c9a1df707a88fba36fd15ccb91011402568062a)
      #03 pc 0000000000112554  /data/app/flutter.soloud.example-k-p97bVufhg8O0OMd1yCmA==/lib/arm64/libflutter_soloud_plugin.so (BuildId: 9c9a1df707a88fba36fd15ccb91011402568062a)
      #04 pc 0000000000155370  /data/app/flutter.soloud.example-k-p97bVufhg8O0OMd1yCmA==/lib/arm64/libflutter_soloud_plugin.so (BuildId: 9c9a1df707a88fba36fd15ccb91011402568062a)
      #05 pc 000000000001db30  /system/lib64/libaaudio.so (aaudio::AudioStream::maybeCallDataCallback(void*, int)+208) (BuildId: 3b3e2eff2488e0adaa1ff63da687463b)
      #06 pc 0000000000024714  /system/lib64/libaaudio.so (aaudio::AudioStreamLegacy::callDataCallbackFrames(unsigned char*, int)+320) (BuildId: 3b3e2eff2488e0adaa1ff63da687463b)
      #07 pc 000000000002c3cc  /system/lib64/libaaudio.so (FixedBlockReader::processVariableBlock(unsigned char*, int)+200) (BuildId: 3b3e2eff2488e0adaa1ff63da687463b)
      #08 pc 0000000000024ef4  /system/lib64/libaaudio.so (aaudio::AudioStreamLegacy::processCallbackCommon(int, void*)+1168) (BuildId: 3b3e2eff2488e0adaa1ff63da687463b)
      #09 pc 000000000007d034  /system/lib64/libaudioclient.so (android::AudioTrack::processAudioBuffer()+3044) (BuildId: 36a8c3e1296b171698432326efcd874d)
      #10 pc 000000000007c220  /system/lib64/libaudioclient.so (android::AudioTrack::AudioTrackThread::threadLoop()+484) (BuildId: 36a8c3e1296b171698432326efcd874d)
      #11 pc 00000000000135bc  /system/lib64/libutils.so (android::Thread::_threadLoop(void*)+224) (BuildId: f52e94e6224d7e15faba92ee0326b191)
      #12 pc 00000000000c4cb8  /system/lib64/libandroid_runtime.so (android::AndroidRuntime::javaThreadShell(void*)+140) (BuildId: 58119cd499c9126f89ff7f6888912397)
      #13 pc 00000000000e6890  /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_start(void*)+36) (BuildId: 328a3518945f3e056fc055f1eea1cc35)
      #14 pc 0000000000084b6c  /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+64) (BuildId: 328a3518945f3e056fc055f1eea1cc35)
Lost connection to device.

Exited.

It seems that miniaudio doesn't wait for a buffer to be freed and AAudio gets closed before that.

@alnitak alnitak added the bug Something isn't working label Mar 23, 2024
@alnitak alnitak self-assigned this Mar 23, 2024
@alnitak
Copy link
Owner Author

alnitak commented Mar 23, 2024

I tried the dev miniaudio branch unsuccessfully.

The solution could be to enable AAudio only on Android > 29 letting the other devices use OpenSL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant