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.23k stars 7.05k forks source link

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

Open dumganhar opened 7 years ago

dumganhar commented 7 years ago

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

wanglailai commented 6 years ago

Will this bug fixed at 3.17 version?

formatCvt commented 6 years ago

confirm bug on cocos2d-x version 3.16 too

wbbtcool commented 5 years ago

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");
Vivek-Excellentric commented 2 years ago

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

jhyoo2 commented 2 years ago

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.

QuiQiJingFeng commented 1 year ago

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

QuiQiJingFeng commented 3 months ago

自己解码播放就可以避免这个问题了