Audio issue in 3.17

Audio issue in 3.17


@slackmoehrle by looking at the stack trace it seems to come from onEnterForeground and crash on PcmAudioService::resume()

 #00  pc 00000000003f3fce  /data/app/ (_ZN7cocos2d12experimental15PcmAudioService6resumeEv+5)
 #01  pc 00000000003e18d3  /data/app/ (_ZN7cocos2d12experimental15AudioEngineImpl17onEnterForegroundEPNS_11EventCustomE+10)

0 PcmAudioService::resume()
1 AudioEngineImpl::onEnterForeground(EventCustom* event)

@tink3r_t I am usingf mp3 format. You think that format can cause an issue?



Sorry, what I mean but didn’t write was do you have anything custom there or just stock engine code?


@slackmoehrle NP! No changes just the stock 3.17 engine code.



Any ideas how we can fix this? It’s pushing our game crash rate over Google Console threshold. Which it’s very bad now due to the new alg changed.



@drelaptop any ideas?


Any ideas guys @slackmoehrle @drelaptop ?? I understand you guys are super busy with deprecation of opengl but helping with the latest 3.17 release issues will help us all.



sorry for a long response. is it possible to add a case to reproduce this issue? @vkreal2


NP @drelaptop!

Sorry, we can’t find a repro… just the logs in Play console below. Any help be greatly appreciated!

pid: 0, tid: 0 >>> <<<

  #00  pc 00000000003f3fce  /data/app/ (_ZN7cocos2d12experimental15PcmAudioService6resumeEv+5)
  #01  pc 00000000003e18d3  /data/app/ (_ZN7cocos2d12experimental15AudioEngineImpl17onEnterForegroundEPNS_11EventCustomE+10)
  #02  pc 000000000050c384  /data/app/
  #03  pc 0000000000507bc4  /data/app/ (_ZN7cocos2d15EventDispatcher24dispatchEventToListenersEPNS0_19EventListenerVectorERKSt8functionIFbPNS_13EventListenerEEE+412)
  #04  pc 00000000005082c8  /data/app/ (_ZN7cocos2d15EventDispatcher13dispatchEventEPNS_5EventE+336)
  #05  pc 00000000003aad3b  /data/app/ (Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeOnResume+82)
  #06  pc 000000000072fd6d  /data/app/


Please check this PR. It fixes above issue.


@umairjaved6 Thank you!!!


@drelaptop @umairjaved6

Looked at the PR. Sorry, I might be missing something but how is _playItf not being initialized when calling pause or resume? Please help me understand this fix for my education.


check PcmAudioService::init.

r = (*_engineItf)->CreateAudioPlayer(_engineItf, &_playObj, &source, &sink,
                                     sizeof(ids) / sizeof(ids[0]), ids, req);
SL_RETURN_VAL_IF_FAILED(r, false, "CreateAudioPlayer failed");

r = (*_playObj)->Realize(_playObj, SL_BOOLEAN_FALSE);
SL_RETURN_VAL_IF_FAILED(r, false, "Realize failed");

r = (*_playObj)->GetInterface(_playObj, SL_IID_PLAY, &_playItf);
SL_RETURN_VAL_IF_FAILED(r, false, "GetInterface SL_IID_PLAY failed");

If any of these three fails, _playItf will not get initialised. Currently, I dont know under what conditions these checks fail.


Out of the init() method, at AudioPlayerProvider::AudioPlayerProvider().

new PcmAudioService() success, but if the init() method failed. might lead to _pcmAudioService !=null and _playItf = null.

_pcmAudioService = new (std::nothrow) PcmAudioService(engineItf, outputMixObject);
_pcmAudioService->init(_mixController, 2, deviceSampleRate, bufferSizeInFrames * 2);

next see the AudioPlayerProvider::pause() and resume()

if (_pcmAudioService != nullptr)

it called,

SLresult r = (*_playItf)->SetPlayState(_playItf, SL_PLAYSTATE_PLAYING); 
SL_RETURN_IF_FAILED(r, "PcmAudioService::resume failed");

crash occurs when _playItf = null


Your patch make the audio more stable, crash will not occurs even if init failed. that’s wonderful. I try to reproduce this issue, but I failed. even no better method, I select to to simulate init failed, crash will occur when calling pause(). with your patch, even init failed, crash won’t occur, sure, the audio can’t work, all in silence, but other feature works.


@drelaptop I can live with audio failing compare to a crash :slight_smile: Thanks for the explanation!


with regret this is not a perfect solution, I will try to test more android device to test if init will failed. solve it if reproduce.

Could we know the crash occurs in what android device, and what android version by Google Play Console ? @vkreal2


Test audio: (play -> pause -> resume) on Device

Xiaomi MI 4, Android 4.4.4, API 19

Vivo Y66, Android 6.0.1 API 23

Samsung SM-G9350, Android 8.0, API 26

No crash occur, might this crash only occur on some specific android device.


@drelaptop check this.



Just saying: Huawei sucks and I had a lot of audio issues on Huawei device. It’s best to use .ogg format or even wav (but it’s big).

Hope you’ll fix these issues. Fingers crossed.


@drelaptop devices below. I will get rest of data tomorrow.

Canvas Spark 4G (Q4201)
itel A42 Plus (itel-A42Plus)	
A40 Indian (A40_Indian)	
U50A MAX (U50A_MAX)	
Galaxy Grand Prime Plus (grandpplte)	
i10 (i10)	
Griffe T1 (Griffe_T1)	
IF9035_IN (A62)	
E1 (QMobile_E1)