igorski / MWEngine

Audio engine and DSP library for Android, written in C++ providing low latency performance within a musical context, while providing a Java/Kotlin API. Supports both OpenSL and AAudio.
MIT License
264 stars 45 forks source link

Crash that seems to be about Events when no has been added/removed #165

Closed vustav closed 2 years ago

vustav commented 2 years ago

I'm getting this crash when using a randomizing-feature in my app. What's happening is instruments are getting muted/unmuted, SampleEvents are getting new samples, SynthInstruments are getting new properties and effects are being removed/new added. No events are added or removed. This is while the engine is running.

I'm not very good at reading these stack traces but it seems to be something with MWEngine::Sequencer::collectSequencedEvents(MWEngine::BaseInstrument*, int, int, int, bool) and std::out_of_range: vector? That's why I'm mentioning not adding/removing events.

2022-06-08 11:30:32.956 3233-3233/? A/DEBUG: 2022-06-08 11:30:32.957 3233-3233/? A/DEBUG: Build fingerprint: 'Ulefone/Armor_7_EEA/Armor_7:9/PPR1.180610.011/1577252479:user/release-keys' 2022-06-08 11:30:32.957 3233-3233/? A/DEBUG: Revision: '0' 2022-06-08 11:30:32.957 3233-3233/? A/DEBUG: ABI: 'arm64' 2022-06-08 11:30:32.957 3233-3233/? A/DEBUG: pid: 2991, tid: 3119, name: Thread-2 >>> com.kiefer.llppdrums <<< 2022-06-08 11:30:32.957 3233-3233/? A/DEBUG: signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr -------- 2022-06-08 11:30:32.957 3233-3233/? A/DEBUG: Abort message: 'terminating with uncaught exception of type std::out_of_range: vector' 2022-06-08 11:30:32.957 3233-3233/? A/DEBUG: x0 0000000000000000 x1 0000000000000c2f x2 0000000000000006 x3 0000000000000008 2022-06-08 11:30:32.957 3233-3233/? A/DEBUG: x4 fefeff716e736264 x5 fefeff716e736264 x6 fefeff716e736264 x7 7f7f7f7f7f7f7f7f 2022-06-08 11:30:32.957 3233-3233/? A/DEBUG: x8 0000000000000083 x9 00000079a2eb6390 x10 fffffff87ffffbdf x11 0000000000000001 2022-06-08 11:30:32.957 3233-3233/? A/DEBUG: x12 0000000000000018 x13 0000000062a06c38 x14 0030970451454344 x15 0000519236277758 2022-06-08 11:30:32.957 3233-3233/? A/DEBUG: x16 00000079a2eef2c8 x17 00000079a2e2d1d0 x18 0000000000000000 x19 0000000000000baf 2022-06-08 11:30:32.957 3233-3233/? A/DEBUG: x20 0000000000000c2f x21 0000000000000083 x22 ffffff80ffffffc8 x23 00000079046138b0 2022-06-08 11:30:32.957 3233-3233/? A/DEBUG: x24 0000007904613790 x25 00000079046137d0 x26 0000000000000100 x27 0000000000000800 2022-06-08 11:30:32.957 3233-3233/? A/DEBUG: x28 000000791c7c45b4 x29 0000007904613700 2022-06-08 11:30:32.957 3233-3233/? A/DEBUG: sp 00000079046136c0 lr 00000079a2e21a60 pc 00000079a2e21a8c 2022-06-08 11:30:32.965 3233-3233/? A/DEBUG: backtrace: 2022-06-08 11:30:32.965 3233-3233/? A/DEBUG: #00 pc 0000000000021a8c /system/lib64/libc.so (abort+124) 2022-06-08 11:30:32.965 3233-3233/? A/DEBUG: #01 pc 000000000016957c /data/app/com.kiefer.llppdrums-m1wLnbt2O-h0SyqJrtBi6w==/base.apk (offset 0x2afc000) 2022-06-08 11:30:32.965 3233-3233/? A/DEBUG: #02 pc 00000000001696d4 /data/app/com.kiefer.llppdrums-m1wLnbt2O-h0SyqJrtBi6w==/base.apk (offset 0x2afc000) 2022-06-08 11:30:32.966 3233-3233/? A/DEBUG: #03 pc 00000000001665c4 /data/app/com.kiefer.llppdrums-m1wLnbt2O-h0SyqJrtBi6w==/base.apk (offset 0x2afc000) 2022-06-08 11:30:32.966 3233-3233/? A/DEBUG: #04 pc 0000000000165bf0 /data/app/com.kiefer.llppdrums-m1wLnbt2O-h0SyqJrtBi6w==/base.apk (offset 0x2afc000) 2022-06-08 11:30:32.966 3233-3233/? A/DEBUG: #05 pc 0000000000165b4c /data/app/com.kiefer.llppdrums-m1wLnbt2O-h0SyqJrtBi6w==/base.apk (offset 0x2afc000) (cxa_throw+112) 2022-06-08 11:30:32.966 3233-3233/? A/DEBUG: #06 pc 00000000000c52fc /data/app/com.kiefer.llppdrums-m1wLnbt2O-h0SyqJrtBi6w==/base.apk (offset 0x2afc000) 2022-06-08 11:30:32.966 3233-3233/? A/DEBUG: #07 pc 00000000000c52b8 /data/app/com.kiefer.llppdrums-m1wLnbt2O-h0SyqJrtBi6w==/base.apk (offset 0x2afc000) (std::ndk1::vector_base_common::__throw_out_of_range() const+28) 2022-06-08 11:30:32.966 3233-3233/? A/DEBUG: #08 pc 00000000000cfdf4 /data/app/com.kiefer.llppdrums-m1wLnbt2O-h0SyqJrtBi6w==/base.apk (offset 0x2afc000) (std::ndk1::vector<MWEngine::BaseAudioEvent, std::__ndk1::allocator<MWEngine::BaseAudioEvent>>::at(unsigned long)+64) 2022-06-08 11:30:32.966 3233-3233/? A/DEBUG: #09 pc 00000000000cf990 /data/app/com.kiefer.llppdrums-m1wLnbt2O-h0SyqJrtBi6w==/base.apk (offset 0x2afc000) (MWEngine::Sequencer::collectSequencedEvents(MWEngine::BaseInstrument, int, int, int, bool)+292) 2022-06-08 11:30:32.966 3233-3233/? A/DEBUG: #10 pc 00000000000cf78c /data/app/com.kiefer.llppdrums-m1wLnbt2O-h0SyqJrtBi6w==/base.apk (offset 0x2afc000) (MWEngine::Sequencer::getAudioEvents(std::__ndk1::vector<MWEngine::AudioChannel, std::ndk1::allocator<MWEngine::AudioChannel>>, int, int, bool, bool)+380) 2022-06-08 11:30:32.966 3233-3233/? A/DEBUG: #11 pc 00000000000c38d8 /data/app/com.kiefer.llppdrums-m1wLnbt2O-h0SyqJrtBi6w==/base.apk (offset 0x2afc000) (MWEngine::AudioEngine::render(int)+460) 2022-06-08 11:30:32.966 3233-3233/? A/DEBUG: #12 pc 00000000000d3e00 /data/app/com.kiefer.llppdrums-m1wLnbt2O-h0SyqJrtBi6w==/base.apk (offset 0x2afc000) (MWEngine::AAudio_IO::dataCallback(MWEngine::AAudio::AAudioStreamStruct, void, int)+712) 2022-06-08 11:30:32.966 3233-3233/? A/DEBUG: #13 pc 00000000000d3b28 /data/app/com.kiefer.llppdrums-m1wLnbt2O-h0SyqJrtBi6w==/base.apk (offset 0x2afc000) (MWEngine::dataCallback(MWEngine::AAudio::AAudioStreamStruct, void, void, int)+128) 2022-06-08 11:30:32.966 3233-3233/? A/DEBUG: #14 pc 0000000000027aa8 /system/lib64/libaaudio.so (aaudio::AudioStream::maybeCallDataCallback(void, int)+216) 2022-06-08 11:30:32.966 3233-3233/? A/DEBUG: #15 pc 000000000002e344 /system/lib64/libaaudio.so (aaudio::AudioStreamLegacy::callDataCallbackFrames(unsigned char, int)+324) 2022-06-08 11:30:32.966 3233-3233/? A/DEBUG: #16 pc 000000000002e9b8 /system/lib64/libaaudio.so (aaudio::AudioStreamLegacy::processCallbackCommon(int, void)+848) 2022-06-08 11:30:32.966 3233-3233/? A/DEBUG: #17 pc 0000000000074120 /system/lib64/libaudioclient.so (android::AudioTrack::processAudioBuffer()+2520) 2022-06-08 11:30:32.966 3233-3233/? A/DEBUG: #18 pc 000000000007334c /system/lib64/libaudioclient.so (android::AudioTrack::AudioTrackThread::threadLoop()+292) 2022-06-08 11:30:32.966 3233-3233/? A/DEBUG: #19 pc 000000000000fab8 /system/lib64/libutils.so (android::Thread::_threadLoop(void*)+280) 2022-06-08 11:30:32.966 3233-3233/? A/DEBUG: #20 pc 0000000000082f44 /system/lib64/libc.so (pthread_start(void*)+36) 2022-06-08 11:30:32.966 3233-3233/? A/DEBUG: #21 pc 0000000000023324 /system/lib64/libc.so (__start_thread+68) 2022-06-08 11:30:33.718 3237-3237/? E/AEE_AED: execute /system/bin/aee_dumpstate 2022-06-08 11:30:33.759 3238-3238/? E/AEE_AED: execute /system/bin/ls 2022-06-08 11:30:33.776 3239-3239/? E/AEE_AED: execute /system/xbin/showmap 2022-06-08 11:30:33.777 3239-3239/? E/AEE_AED: copy_process: execvp /system/xbin/showmap failed(2), No such file or directory 2022-06-08 11:30:33.785 3237-3237/? E/AEE_DUMPSTATE: copy_file: Copy /proc/m4u/mva to SYS_M4UMVA failed(20), Not a directory 2022-06-08 11:30:33.796 3240-3240/? E/AEE_AED: execute /system/bin/logcat

igorski commented 2 years ago

Well your observation is correct:

h0SyqJrtBi6w==/base.apk (offset 0x2afc000) (std::__ndk1::__vector_base_common::__throw_out_of_range() const+28)
2022-06-08 11:30:32.966 3233-3233/? A/DEBUG: https://github.com/igorski/MWEngine/issues/8 pc 00000000000cfdf4 /data/app/com.kiefer.llppdrums-m1wLnbt2O-h0SyqJrtBi6w==/base.apk (offset 0x2afc000) (std::__ndk1::vector<MWEngine::BaseAudioEvent*, std::__ndk1::allocatorMWEngine::BaseAudioEvent*>::at(unsigned long)+64)

indicates that the iterator is moving beyond the total vector size, which would hint that something is removed during this operation even if you're not consciously adding/removing events. Out of interest what are the properties that are being changed on the instrument (as this might affect event positioning), maybe you can share some pseudo-code of your implementation and how you are timing / invoking this randomization ?

Either way, I pushed some code in 188d32f5528ea0454d1e760730fc296bbd7699f9 which makes the Sequencer use a different event iterator approach which should catch out of range errors, this might help your case.

vustav commented 2 years ago

Properties randomized are:

The events on these instruments represents drums and I made this a long time ago. I see now I start by setting sustain and release to 0. Don't remember why but probably just to keep it simple. Can this cause problems?

I'll try the new code tonight! This is not something I can reproduce on demand but I should at least get a feel for if it helps or not.

vustav commented 2 years ago

No crashes like this tonight, seems the catch solved it for me!