cocos2d-x icon indicating copy to clipboard operation
cocos2d-x copied to clipboard

[android] Dead lock in wilhelm (OpenSLES) while destroying OpenSLES object right after it was initialized

Open dumganhar opened this issue 7 years ago • 6 comments

  • cocos2d-x version: v3.15.1
  • devices test on: Android 7.0
  • developing environments
    • NDK version: r10e
    • Xcode version:
    • VS version:
    • browser type and version:

Steps to Reproduce:

    schedule([](float dt){
        for (int i = 0; i < 20; ++i) {
            AudioEngine::play2d("fonts/audio_music_004.mp3");
            std::this_thread::sleep_for(std::chrono::milliseconds(5));
            AudioEngine::stopAll();
        }
    }, "bbbb");

Result:

06-28 15:38:30.240 6674-6707/org.cocos2dx.cpp_empty_test V/UrlAudioPlayer: Current UrlAudioPlayer instance count: 1
06-28 15:38:30.240 6674-6707/org.cocos2dx.cpp_empty_test V/UrlAudioPlayer: UrlAudioPlayer::prepare: assets/fonts/audio_music_004.mp3, SL_DATALOCATOR_ANDROIDFD, 52, 468084, 1454144
06-28 15:38:30.251 6674-6707/org.cocos2dx.cpp_empty_test V/UrlAudioPlayer: UrlAudioPlayer::stop (0xe36c9020, 9746)
06-28 15:38:30.251 6674-6707/org.cocos2dx.cpp_empty_test V/AudioEngineImpl: Removing player id=9746, state:4
06-28 15:38:30.251 6674-6707/org.cocos2dx.cpp_empty_test V/UrlAudioPlayer: UrlAudioPlayer::destroy() 0xe36c9020
06-28 15:38:30.263 6674-7250/org.cocos2dx.cpp_empty_test E/libOpenSLES: frameworks/wilhelm/src/android/AudioPlayer_to_android.cpp:785: pthread_mutex_lock_timeout_np returned 110
06-28 15:38:30.283 6674-7250/org.cocos2dx.cpp_empty_test E/libOpenSLES: frameworks/wilhelm/src/android/AudioPlayer_to_android.cpp:785: pthread_mutex_lock_timeout_np returned 110
06-28 15:38:30.313 6674-7250/org.cocos2dx.cpp_empty_test E/libOpenSLES: frameworks/wilhelm/src/android/AudioPlayer_to_android.cpp:785: pthread_mutex_lock_timeout_np returned 110
06-28 15:38:30.354 6674-7250/org.cocos2dx.cpp_empty_test E/libOpenSLES: frameworks/wilhelm/src/android/AudioPlayer_to_android.cpp:785: pthread_mutex_lock_timeout_np returned 110
06-28 15:38:30.404 6674-7250/org.cocos2dx.cpp_empty_test E/libOpenSLES: frameworks/wilhelm/src/android/AudioPlayer_to_android.cpp:785: pthread_mutex_lock_timeout_np returned 110
06-28 15:38:30.504 6674-7250/org.cocos2dx.cpp_empty_test E/libOpenSLES: frameworks/wilhelm/src/android/AudioPlayer_to_android.cpp:785: pthread_mutex_lock_timeout_np returned 110
06-28 15:38:30.505 6674-7250/org.cocos2dx.cpp_empty_test W/libOpenSLES: frameworks/wilhelm/src/android/AudioPlayer_to_android.cpp:785: pthread 0xd2561920 (tid 7250) sees object 0xe320a800 was locked by pthread 0xe8a7f920 (tid 6707) at frameworks/wilhelm/src/itf/IObject.c:411

It's a bug of Android System. Please also refer to http://grokbase.com/t/gg/android-ndk/156tayqf1c/opensl-deadlock-issue http://webmail.dev411.com/p/gg/android-ndk/154fhnm2ce/why-does-opensl-destroy-function-block-forever-on-some-devices https://github.com/cocos2d/cocos2d-x/issues/12479 https://github.com/cocos2d/cocos2d-x/pull/11762

dumganhar avatar Jun 28 '17 07:06 dumganhar

Will this bug fixed at 3.17 version?

wanglailai avatar Jan 19 '18 13:01 wanglailai

confirm bug on cocos2d-x version 3.16 too

formatCvt avatar Mar 25 '18 14:03 formatCvt

This bug will still on 3.17.1. I use schedule function delay play sound. Temporarily circumvented this problem.

    node->scheduleOnce([=](float time){
        AudioEngine::play2d(filePath);
    }, 0.01, "play_sound");

wbbtcool avatar Oct 08 '19 06:10 wbbtcool

I still face problems after putting delay. Anyone has the solution?

Vivek-Excellentric avatar Dec 14 '21 14:12 Vivek-Excellentric

I also found the same problem.. How can I not solve this? It's a problem because the game freezes. It's a really big problem.

jhyoo2 avatar Jul 25 '22 12:07 jhyoo2

播放的时候会返回一个Id,记录下这个id开始播放的时间,销毁的时候判断一下这个时间是否超过比如0.5秒,如果超过则销毁,否则延迟到0.5秒后再销毁就可以了

QuiQiJingFeng avatar Oct 24 '23 08:10 QuiQiJingFeng