Skip to content

Crashed with Android 4.4.2 #16229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
alfogrillo opened this issue Jul 27, 2016 · 31 comments
Closed

Crashed with Android 4.4.2 #16229

alfogrillo opened this issue Jul 27, 2016 · 31 comments
Milestone

Comments

@alfogrillo
Copy link
Contributor

alfogrillo commented Jul 27, 2016

I'm testing the v3 branch because it include @dumganhar's #15875 audio patch for Android.

However with a simple test project I noticed that app crashes when uses AudioEngine.
I had the problem only with Android 4.4.2 for now (Android 5, 6 seems ok).

This is my sample project:
AudioCrashTest_mirror.zip
It is a slight modification of cpp_empty_test

Finally this is my crash dump:

********** Crash dump: **********
Build fingerprint: 'asus/WW_K010/K010:4.4.2/KOT49H/WW_user_2.2.33.141_20150512:user/release-keys'
pid: 27634, tid: 27661, name: Thread-3569  >>> org.cocos2dx.Android4Test <<<
signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
Stack frame #00  pc 00048bf6  /system/lib/libc.so (tgkill+22)
Stack frame #01  pc 00000005  <unknown>
Stack frame #02  pc 0018e705  /system/lib/libhoudini.so.4.0.8.45720
Crash dump is completed
  • cocos2d-x version: v3 branch
  • devices test on: Samsung Galaxy S4, Asus Transformer TF103C
  • developing environments
    • NDK version: 10e, 11c

Steps to Reproduce:

  1. Create a new cocos project
  2. Add/Replace files contained in AudioCrashTest.zip
  3. Execute on an Android 4.4.2 device
@dumganhar
Copy link

The crash stack seems to say nothing. :(

@dumganhar
Copy link

The attachment url is broken.

@alfogrillo
Copy link
Contributor Author

@dumganhar
I now, not much information! :-(
If I get something more specific I will post!
Have you the possibility to install 4.4.2 on one of your devices?
I uploaded the project again, now should work!

@dumganhar
Copy link

I don't have a 4.4.2 device. But it works on Android 4.4.4.
Could you help to debug which line cause the crash?

@dumganhar
Copy link

@Drakon-Cocos, the attachment still could not be downloaded. please check it again.

@alfogrillo
Copy link
Contributor Author

@dumganhar
I uploaded again! :-/

@dumganhar
Copy link

Thanks. It could be downloaded.

@alfogrillo
Copy link
Contributor Author

@dumganhar
I think identified the line that makes the program to crash.
Look this log:

07-27 12:57:57.315 17758-17811/org.cocos2dx.Android4Test D/cocos2d-x debug info: Preloading sounds...
07-27 12:57:57.315 17758-17811/org.cocos2dx.Android4Test D/ThreadPool: before reset
07-27 12:57:57.315 17758-17811/org.cocos2dx.Android4Test D/ThreadPool: after reset
07-27 12:57:57.325 17758-17811/org.cocos2dx.Android4Test I/AudioPlayerProvider: deviceSampleRate: 48000, bufferSizeInFrames: 1152
07-27 12:57:57.325 17758-17811/org.cocos2dx.Android4Test D/AudioPlayerProvider: Android API level: 19
07-27 12:57:57.325 17758-17811/org.cocos2dx.Android4Test V/AudioMixerController: In the constructor of AudioMixerController!
07-27 12:57:57.335 17758-17811/org.cocos2dx.Android4Test V/AudioPlayerProvider: [AudioPlayerProvider::preloadEffect]: assets/sounds/s01.wav
07-27 12:57:57.335 17758-17811/org.cocos2dx.Android4Test V/AudioPlayerProvider: (assets/sounds/s01.wav) file size: 23546
07-27 12:57:57.335 17758-17811/org.cocos2dx.Android4Test V/AudioPlayerProvider: After getFileInfo: assets/sounds/s01.wav
07-27 12:57:57.335 17758-17811/org.cocos2dx.Android4Test V/AudioPlayerProvider: After preloadEffect with fileInfo: assets/sounds/s01.wav
07-27 12:57:57.335 17758-17811/org.cocos2dx.Android4Test V/AssetFd: ~AssetFd: 64
07-27 12:57:57.335 17758-17833/org.cocos2dx.Android4Test V/AudioPlayerProvider: AudioPlayerProvider::preloadEffect: (assets/sounds/s01.wav)
07-27 12:57:57.345 17758-17833/org.cocos2dx.Android4Test V/AudioDecoder: Play callback registered
07-27 12:57:57.345 17758-17811/org.cocos2dx.Android4Test V/AudioPlayerProvider: [AudioPlayerProvider::preloadEffect]: assets/sounds/s02.wav
07-27 12:57:57.345 17758-17811/org.cocos2dx.Android4Test V/AudioPlayerProvider: (assets/sounds/s02.wav) file size: 41310
07-27 12:57:57.345 17758-17811/org.cocos2dx.Android4Test V/AudioPlayerProvider: After getFileInfo: assets/sounds/s02.wav
07-27 12:57:57.345 17758-17811/org.cocos2dx.Android4Test D/ThreadPool: before stretchPool
07-27 12:57:57.345 17758-17811/org.cocos2dx.Android4Test D/ThreadPool: before setThread(i);
07-27 12:57:57.345 17758-17811/org.cocos2dx.Android4Test D/ThreadPool: before reset
07-27 12:57:57.345 17758-17811/org.cocos2dx.Android4Test A/libc: /Volumes/Android/buildbot/out_dirs/aosp-ndk-r11-release/build/tmp/build-72234/build-libc++/ndk/sources/cxx-stl/llvm-libc++/../llvm-libc++abi/libcxxabi/src/abort_message.cpp:74: void abort_message(const char *, ...): assertion "terminating" failed
07-27 12:57:57.345 17758-17811/org.cocos2dx.Android4Test A/libc: Fatal signal 6 (SIGABRT) at 0x0000455e (code=-6), thread 17811 (Thread-1591)

The program crashes always when try to preload the second sound:

  1. ThreadPool::stretchPool is called
  2. Then ThreadPool::setThread is called
  3. ThreadPool::setThread crashes here: _threads[tid].reset(new(std::nothrow) std::thread(f));. Print after reset is missing!

Here the full ThreadPool::setThread code:

void ThreadPool::setThread(int tid)
{
    std::shared_ptr<std::atomic<bool>> abort_ptr(
            _abortFlags[tid]); // a copy of the shared ptr to the flag

    auto f = [this, tid, abort_ptr/* a copy of the shared ptr to the abort */]() {
        std::atomic<bool>& abort = *abort_ptr;
        Task task;
        bool isPop = _taskQueue.pop(task);
        while (true)
        {
            while (isPop)
            {  // if there is anything in the queue
                std::unique_ptr<std::function<void(int)>> func(
                        task.callback); // at return, delete the function even if an exception occurred
                (*task.callback)(tid);
                if (abort)
                    return;  // the thread is wanted to stop, return even if the queue is not empty yet
                else
                    isPop = _taskQueue.pop(task);
            }
            // the queue is empty here, wait for the next command
            std::unique_lock<std::mutex> lock(_mutex);
            _idleThreadNumMutex.lock();
            ++_idleThreadNum;
            _idleThreadNumMutex.unlock();

            *_idleFlags[tid] = true;
            _cv.wait(lock, [this, &task, &isPop, &abort]() {
                isPop = _taskQueue.pop(task);
                return isPop || _isDone || abort;
            });
            *_idleFlags[tid] = false;
            _idleThreadNumMutex.lock();
            --_idleThreadNum;
            _idleThreadNumMutex.unlock();

            if (!isPop)
                return;  // if the queue is empty and isDone == true or *flag then return
        }
    };

    LOGD("before reset");
    _threads[tid].reset(
            new(std::nothrow) std::thread(f)); // compiler may not support std::make_unique()
    LOGD("after reset");
}

@dumganhar
Copy link

It looks like you were using clang + c++_static to compile your project.
Could you switch to gcc + gnustl_static to test?

About how to switch to gcc, you could modify (cocos2d-x/tools/cocos2d-console/plugins/plugin_compile/build_android.py), search clang, replace with 4.8 or 4.9

    def get_toolchain_version(self, ndk_root, compile_obj):
        return 'clang'  # --> '4.8' or '4.9'

@alfogrillo
Copy link
Contributor Author

@dumganhar
I tried to use '4.9'.
I generated a new project e recompiled everything.
It continues to crash, but the cause seems different:

D/dalvikvm(21514): Trying to load lib /data/app-lib/org.cocos2dx.Android4Test-1/libMyGame.so 0x43c718c0
D/houdini (21514): [21514] Open Native Library /data/app-lib/org.cocos2dx.Android4Test-1/libMyGame.so failed.
E/dalvikvm(21514): Houdini dlopen("/data/app-lib/org.cocos2dx.Android4Test-1/libMyGame.so") failed: Can't load ARM library
E/AndroidRuntime(21514): Process: org.cocos2dx.Android4Test, PID: 21514
E/AndroidRuntime(21514): java.lang.UnsatisfiedLinkError: dlopen failed: "/data/app-lib/org.cocos2dx.Android4Test-1/libMyGame.so" has unexpected e_machine: 40
E/AndroidRuntime(21514):    at org.cocos2dx.lib.Cocos2dxActivity.onLoadNativeLibraries(Cocos2dxActivity.java:248)
E/AndroidRuntime(21514):    at org.cocos2dx.lib.Cocos2dxActivity.onCreate(Cocos2dxActivity.java:264)

When I start cocos run I see NDK_TOOLCHAIN_VERSION=4.9, this should be a confirmation I'm using gcc. The NDK is 11c

@dumganhar
Copy link

I have no idea about dlopen error really.

@minggo ,any thoughts about @Drakon-Cocos posted above?

@minggo
Copy link
Contributor

minggo commented Jul 28, 2016

@Drakon-Cocos will you please use latest github codes and try again?

@alfogrillo
Copy link
Contributor Author

alfogrillo commented Jul 28, 2016

@minggo
Yes I'm going to pull v3 branch and redo the test!

EDIT: have you switched to gcc + gnustl_static in the last commits?

@alfogrillo
Copy link
Contributor Author

I found out some interesting things:

  • The problem in opening the cocos library is due to the fact that in the file proj.android-studio/app/project.properties there is the line
    target=android-21
    replacing with (api 19 are 4.4.2)
    target=android-19
    project works!
    I think this file should contain as default the lowest Android api supported by cocos2d-x
  • The audio crash seems to be related to the usage of clang. Using gcc + gnustl_static makes the audio to work

@minggo
Copy link
Contributor

minggo commented Jul 28, 2016

Yep, we found clang+gnustl_static may cause crash issues. target=android-21 is needed by AudioEngine to optimize the performance, but it should not cause crash if running with Android OS version lower than 21. @dumganhar could you please double check it?

@dumganhar
Copy link

target section could be set to 19.
Currently,

  • we need at least API 17 to get the device sample rate & sample buffer size.

Cocos2dxHelper.java

            int sampleRate = 44100;
            int bufferSizeInFrames = 192;

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { // API 17
                AudioManager am = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE);
                String strSampleRate = am.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE);
                String strBufferSizeInFrames = am.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER);

                sampleRate = Integer.parseInt(strSampleRate);
                bufferSizeInFrames = Integer.parseInt(strBufferSizeInFrames);

                Log.d(TAG, "sampleRate: " + sampleRate + ", framesPerBuffer: " + bufferSizeInFrames);
            } else {
                Log.d(TAG, "android version is lower than " + Build.VERSION_CODES.JELLY_BEAN_MR1);
            }
  • we need at least API 19 to implement full screen logic (hide the virtual button bar at the bottom)

Cocos2dxActivity.java

    protected void hideVirtualButton() {

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {  // API 19

            getWindow().getDecorView().setSystemUiVisibility(
                    View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
                            | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
                            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
        }
    }

@minggo , therefore, we need to change API 21 to API 19

@ryanxia2016
Copy link

ryanxia2016 commented Jul 28, 2016

@minggo
I read this Issue and got the information: "gcc + gnustl_static is a better choose now"
So, I switched my config from clang to 4.8 + gnustl_static

But, the game crashed at IdeaTab (x86), previous version with clang is OK.
quite confused....

clang+gnustl_static will cause arm to crash, and gcc +gnustl_static will cause x86 to crash?

saddly story...

@minggo
Copy link
Contributor

minggo commented Jul 28, 2016

@ryanxia2016 please use gcc 4.9.

@minggo
Copy link
Contributor

minggo commented Jul 28, 2016

@dumganhar ok, i will change to 19.

@minggo
Copy link
Contributor

minggo commented Jul 28, 2016

I changed to api 19 in #16248

@minggo
Copy link
Contributor

minggo commented Jul 28, 2016

Oh, we need api 21 to fix compiling issue if using api lever 21+. Detail information can refer to #15891.

@Drakon-Cocos did you fix the issue if using gcc+api21?

@alfogrillo
Copy link
Contributor Author

@minggo
On Android 4.4.2 with api 21 and gcc 4.9 I get this (with cpp_empty_test):

D/dalvikvm(21514): Trying to load lib /data/app-lib/org.cocos2dx.Android4Test-1/libMyGame.so 0x43c718c0
D/houdini (21514): [21514] Open Native Library /data/app-lib/org.cocos2dx.Android4Test-1/libMyGame.so failed.
E/dalvikvm(21514): Houdini dlopen("/data/app-lib/org.cocos2dx.Android4Test-1/libMyGame.so") failed: Can't load ARM library
E/AndroidRuntime(21514): Process: org.cocos2dx.Android4Test, PID: 21514
E/AndroidRuntime(21514): java.lang.UnsatisfiedLinkError: dlopen failed: "/data/app-lib/org.cocos2dx.Android4Test-1/libMyGame.so" has unexpected e_machine: 40
E/AndroidRuntime(21514):    at org.cocos2dx.lib.Cocos2dxActivity.onLoadNativeLibraries(Cocos2dxActivity.java:248)
E/AndroidRuntime(21514):    at org.cocos2dx.lib.Cocos2dxActivity.onCreate(Cocos2dxActivity.java:264)

@ryanxia2016
Copy link

@minggo
4.9 still crash at IdeaTab, clang is ok

is any document describe the key difference between 4.8 / 4.9 and clang?

@minggo
Copy link
Contributor

minggo commented Jul 28, 2016

@ryanxia2016 No, there is not a document. Is there any crash log? What's you engine version? Can cpp-empty-test or cpp-tests work on that machine.

@Drakon-Cocos It is strange. I will try to find Samsung Galaxy S4 or Asus Transformer TF103C to test. Could you please use NDK r12b to have a test?

@alfogrillo
Copy link
Contributor Author

@minggo
I think you could have a try with any Android 4.4.2 device.
I'll test Ndk r12b (I think you mean with api 21)!

@ryanxia2016
Copy link

@minggo
I am using a self-modified version of quick-x (based on 3.3 but merged a lot of bug fix and PR), so I am not confirm the issue is connected with latest cocos2d-x version.

I will try later.

@alfogrillo
Copy link
Contributor Author

@minggo
Ndk r12b does not change the thing: cpp_empty_test crashes with Android 4.4.2 when using api 21

@minggo
Copy link
Contributor

minggo commented Jul 29, 2016

@Drakon-Cocos you said it is Android OS related, not device related? I will try to find a device with Android 4.4.2.

@minggo
Copy link
Contributor

minggo commented Jul 29, 2016

Yep, i can reproduce it, the error says failed: dlopen failed: cannot locate symbol "atof" referenced by "libcpp_empty_test.so".... I have to replace atof with std::atof though i think i replaced it.

@minggo
Copy link
Contributor

minggo commented Jul 29, 2016

Can not resolve it just replace ::atof with std::atof because the are the same. So have to use API 19.

@minggo
Copy link
Contributor

minggo commented Jul 29, 2016

fixed in #16248, use api 19

@minggo minggo closed this as completed Jul 29, 2016
@minggo minggo added this to the 3.13 milestone Jul 29, 2016
@minggo minggo changed the title [v3 branch, Android 4.4.2] Crash using AudioEngine Crashed with Android 4.4.2 Jul 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants