所以我正在使用 cocos2dx new AudioEngine,我遇到了这个崩溃:https ://github.com/cocos2d/cocos2d-x/issues/18948 。
0 0x0000000184a5cea8 in CrashIfClientProvidedBogusAudioBufferList ()
1 0x000000018493f270 in AudioConverterConvertComplexBuffer ()
2 0x0000000184939460 in AUSpatialMixer::Render(unsigned int&, AudioTimeStamp const&, unsigned int) ()
3 0x0000000184a62a20 in AUBase::DoRenderBus(unsigned int&, AudioTimeStamp const&, unsigned int, AUOutputElement*, unsigned int, AudioBufferList&) ()
4 0x0000000184a621ac in AUBase::DoRender(unsigned int&, AudioTimeStamp const&, unsigned int, unsigned int, AudioBufferList&) ()
5 0x0000000184a6b550 in AUMethodRender(void*, unsigned int*, AudioTimeStamp const*, unsigned int, unsigned int, AudioBufferList*) ()
6 0x0000000184a5d284 in AUInputElement::PullInput(unsigned int&, AudioTimeStamp const&, unsigned int, unsigned int) ()
7 0x00000001847e8e00 in AUInputFormatConverter2::InputProc(OpaqueAudioConverter*, unsigned int*, AudioBufferList*, AudioStreamPacketDescription**, void*) ()
8 0x000000018474fdd4 in AudioConverterChain::CallInputProc(unsigned int) ()
9 0x000000018474fa64 in AudioConverterChain::FillBufferFromInputProc(unsigned int*, CABufferList*) ()
10 0x000000018472be38 in BufferedAudioConverter::GetInputBytes(unsigned int, unsigned int&, CABufferList const*&) ()
11 0x00000001849906f8 in Resampler2Wrapper::RenderOutput(CABufferList*, unsigned int, unsigned int&) ()
12 0x0000000184752a7c in SampleRateConverter::RenderOutput(CABufferList*, unsigned int, unsigned int&, AudioStreamPacketDescription*) ()
13 0x000000018472bcc8 in BufferedAudioConverter::FillBuffer(unsigned int&, AudioBufferList&, AudioStreamPacketDescription*) ()
14 0x000000018474f65c in AudioConverterChain::RenderOutput(CABufferList*, unsigned int, unsigned int&, AudioStreamPacketDescription*) ()
15 0x000000018472bcc8 in BufferedAudioConverter::FillBuffer(unsigned int&, AudioBufferList&, AudioStreamPacketDescription*) ()
16 0x000000018493ec98 in AudioConverterFillComplexBuffer ()
17 0x00000001847e864c in AUConverterBase::RenderBus(unsigned int&, AudioTimeStamp const&, unsigned int, unsigned int) ()
18 0x00000001846cd07c in AURemoteIO::RenderBus(unsigned int&, AudioTimeStamp const&, unsigned int, unsigned int) ()
19 0x0000000184a62a20 in AUBase::DoRenderBus(unsigned int&, AudioTimeStamp const&, unsigned int, AUOutputElement*, unsigned int, AudioBufferList&) ()
20 0x0000000184a621ac in AUBase::DoRender(unsigned int&, AudioTimeStamp const&, unsigned int, unsigned int, AudioBufferList&) ()
21 0x00000001846ccd28 in AURemoteIO::PerformIO(unsigned int, unsigned int, unsigned int, AudioTimeStamp const&, AudioTimeStamp const&, AudioBufferList const*, AudioBufferList*, int&) ()
22 0x00000001846ce1a0 in AURIOCallbackReceiver_PerformIO ()
23 0x0000000184860018 in _XPerformIO ()
24 0x0000000184a4a5ec in mshMIGPerform ()
25 0x0000000184a4a804 in MSHMIGDispatchMessage ()
26 0x00000001846cd4c0 in AURemoteIO::IOThread::Run() ()
27 0x00000001846d1a40 in AURemoteIO::IOThread::Entry(void*) ()
28 0x0000000184a52630 in CAPThread::Entry(CAPThread*) ()
29 0x00000001808c432c in _pthread_body ()
30 0x00000001808c41f8 in _pthread_start ()
31 0x00000001808c2c38 in thread_start ()
基本上发生的事情是 AudioEngine 正在使用 AlBufferDataStatic,将要读取的数据存储在 char* pcmData 缓冲区中(您可以在此处查看代码:https ://github.com/cocos2d/cocos2d-x/tree/v3/cocos /audio/apple(主要是 AudioCache.mm 和 AudioDecoder.mm)),并且当在 AudioCache 析构函数(从主线程调用)中释放 pcmData 缓冲区时,由于 AURemoteIO 正在轮询,因此存在竞争条件客户端数据(对我来说它在 mp3 中)将其转换为 pcm 到它自己的线程中。
所以问题是:我们能否在 AURemoteIO 线程被释放的那一刻停止使用这个现在释放的 pcmData 缓冲区做任何事情?