cocos2d / cocos2d-x

Cocos2d-x is a suite of open-source, cross-platform, game-development tools utilized by millions of developers across the globe. Its core has evolved to serve as the foundation for Cocos Creator 1.x & 2.x.
https://www.cocos.com/en/cocos2d-x
18.22k stars 7.05k forks source link

cocos2dx ios audioplayer::rotatebufferthread crash #20062

Open wubuduan opened 5 years ago

wubuduan commented 5 years ago
wubuduan commented 5 years ago

补充:我们是一款乙女avg游戏,游戏内会播放大量的音频,音频的大小也比较大,bgm会在1M-3M之间。会频繁的触发播放和停止音频的操作。

PatriceJiang commented 5 years ago

频繁的触发播放和停止音频

I ran the test code added in https://github.com/cocos2d/cocos2d-x/pull/18865, it does not crash. It is not sure that if this is the real reason for the crash.

PatriceJiang commented 5 years ago

Can you run the test code in your codebase? Since your code is customized, I need to confirm if play/stop would cause a crash in your project. @wubuduan

wubuduan commented 5 years ago

Ok,we will try the test code, to confirm if play/stop would cause a crash

wubuduan commented 5 years ago

@PatriceJiang We test in our codebase ,frequently play/stop music, running about 30 minutes on iphone7Plus, it does not crash.

PatriceJiang commented 5 years ago

I tried to reproduce the crash and made no progress for now. If you find anything new please let me know. @wubuduan

wubuduan commented 5 years ago

@PatriceJiang Many thanks, we are trying to reproduce the crash too. When we have new progress, I will tell you.

wubuduan commented 5 years ago

We modified the value of PCMDATA_CACHEMAXSIZE to 100M and gave it to online players for testing. The current problem did not appear again. @PatriceJiang

Volodar commented 5 years ago

Also has this crash in production. issue_crash.txt cocos2d-x-3.17.2 (1528ea01d2749b4ef65e97f79cffa6135fe13c4d)

qoozta commented 5 years ago

This is just a null pointer issue, simply add null checking in AudioPlayer.mm line 284 while (bufferProcessed > 0 && _audioCache) The cause of this crash is OpenAL somehow detected buffer not filling (device lag or audio interruption) then switch state to stop and cocos update will clear the streaming cache, but the above loop is still going and trying to get the buffer which is null.

Edited: A simple way to reproduce this crash is play a long sfx multiple times (> 20 instance), then it should crash.

boyjunqiang commented 5 years ago

This is just a null pointer issue, simply add null checking in AudioPlayer.mm line 284 while (bufferProcessed > 0 && _audioCache) The cause of this crash is OpenAL somehow detected buffer not filling (device lag or audio interruption) then switch state to stop and cocos update will clear the streaming cache, but the above loop is still going and trying to get the buffer which is null.

Edited: A simple way to reproduce this crash is play a long sfx multiple times (> 20 instance), then it should crash.

Do null checking in AudioPlayer.mm does not fix the bug, but increase PCMDATA_CACHEMAXSIZE value to 10485760, this problem is gone.