Why application is dying randomly?

前端 未结 4 672
南笙
南笙 2020-12-13 19:43

I am developing an music player app. All works fine except the app dies suddenly. Sometimes this happens when the app starts, and sometimes after running for long time. Some

相关标签:
4条回答
  • 2020-12-13 19:57

    The error more than likely comes from trying to delete or use a non-initialized pointer.

    Since you are not directly messing with pointers, but using other libraries, it is possible that you are not initializing the library the way they want you to. Or there is a chance the library implementor neglected to initialize their pointers and simply haven't realized it because the error may or may not always reveal itself - as you have discovered.

    Because pointers point to an address in memory, if a pointer is not initialized, it will likely contain a garbage value (not a valid memory address).

    The error comes from trying to access/delete a memory address which does not exist or you do not have access to. The thing that makes it seem random is often memory is already pre-initialized to 0 which is also the value of NULL on most systems. Run your system/app long enough memory becomes more dirty.

    Also, I have found that the chance of encountering 0's when declaring a non-initialized variable varies on different systems, so some systems may experience more crashing than others.

    Personal example:

    I ran into this error when I had instanced a class which had a pointer as a private member, but I forgot to initialize the pointer during class initialization.

    Later when that class destructed it was trying to delete the pointer, however because the pointer was not initialized to NULL, it may or may not have some garbage value, so sometimes it would cause a crash and other times it would not.

    Here's a stripped down example of the problem I recently encountered:

    class BadFoo
    {
    public:
        BadFoo() {} // BAD! We didn't initialize the pointer
        ~BadFoo() {
            if (myPtr) {
                delete myPtr; // CRASH HERE IF INVALID ADDRESS
            }
        }
        // OTHER MEMBER FUNCTIONS HERE
    
    private:
        int* myPtr;
    }
    
    
    
    
    class GoodFoo
    {
    public:
        GoodFoo() : myPtr(NULL) {} // GOOD! Can't be garbage value now
        ~GoodFoo() {
            if (myPtr) {
                delete myPtr;
            }
        }
        // OTHER MEMBER FUNCTIONS HERE
    
    private:
        int* myPtr;
    }
    
    0 讨论(0)
  • 2020-12-13 20:05

    Looks like there are a few possibilities (go figure), with quite a bit here on SO.

    Might be running out of memory

    Certainly one of the risks of going native!

    • Fatal Signal 11

    • Android NDK Segmentation Error

    • SIGNAL 11 SIGSEGV crash Android

    Function call being made from two different threads at the same time

    • Invalid heap address and fatal signal 11

    Memory Corruption

    • Fatal signal 11 and INVALID HEAP ADDRESS IN dlfree error when using glShaderBinary

    So... good luck with that one! :/

    0 讨论(0)
  • 2020-12-13 20:09

    I found out the problem.

    I had been initializing a Visualizer class which object inside the onPrepareListener() of a media player.

    So whenever media player was calling prepare() function, the Visualizer object had been created again and again, thus it affected the memory and resulted into app die.

    Removing the Visualizer initialization code from onPrepareListener() and initializing the object only once solved the problem. Now the app no longer crashes.

    0 讨论(0)
  • 2020-12-13 20:15

    In my case, problem was to set a bad Typeface onto a TextView. On process death, a good typeface became bad. And, when user came back to my app, I was not initialising this typeface again, I was using same bad typeface. And so, that triggered fatal error.

    2020-03-06 10:35:58.122 com.xxxxxx.xxxxxx A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x2000 in tid 24474 (com.xxxxxx.xxxxxx), pid 24474 (com.xxxxxx.xxxxxx)
    2020-03-06 10:35:58.141 ? E/DEBUG: failed to readlink /proc/24474/fd/47: No such file or directory
    2020-03-06 10:35:58.141 ? E/DEBUG: failed to readlink /proc/24474/fd/48: No such file or directory
    2020-03-06 10:35:58.176 ? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
    2020-03-06 10:35:58.176 ? A/DEBUG: Build fingerprint: 'google/sdk_gphone_x86/generic_x86:10/QSR1.190920.001/5891938:user/release-keys'
    2020-03-06 10:35:58.176 ? A/DEBUG: Revision: '0'
    2020-03-06 10:35:58.176 ? A/DEBUG: ABI: 'x86'
    2020-03-06 10:35:58.176 ? A/DEBUG: Timestamp: 2020-03-06 10:35:58+0530
    2020-03-06 10:35:58.176 ? A/DEBUG: pid: 24474, tid: 24474, name: com.xxxxxx.xxxxxx  >>> com.xxxxxx.xxxxxx <<<
    2020-03-06 10:35:58.176 ? A/DEBUG: uid: 10140
    2020-03-06 10:35:58.176 ? A/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x2000
    

    Full stach trace

    0 讨论(0)
提交回复
热议问题