OpenSLEngine bugs on I9100 in cocos2d-x 2.0.4

When playing sounds on S2 I9100 Android, it would crashes and having a log “Too many objects” SL_RESULT_MEMORY_FAILURE. After investigating the source code, I found that the OpenSLEngine has bugs that unable to destroy the audio player resource from the driver.

When an sound effect is going the played while the same preloaded sound effect is playing, an extra audio player is created which registers a callback event. This callback is fired right after sound effect is finished (the callback event is PlayOverEvent()), the callback function will destroy the audio player; but, it is unsuccessful and hold the callback thread forever. Thus, audio player resources are created without destroy and eventually exhaust and cause SL_RESULT_MEMORY_FAILURE.

The attached file is the fixed I applied to destroy audio player resource from the caller thread instead of the callback event thread. It adds a checking, if audio player created >= 30, no more audio player created. After that, it also fixes some memory leakage.


OpenSLEngine.cpp.zip (5.5 KB)

It seems it’s a known problem, since it’s mentioned here http://www.cocos2d-x.org/projects/cocos2d-x/wiki/Audio_formats_supported_by_CocosDenshion_on_different_platforms
Probably you should try making a pull request to the official repository at github. Contribute and earn respect, fame and glory ;D