Cocos2dx v3.7 JavaScript game crashes on mobile (Android + iPhone/iOS)

Hi,

I have developer my first game using Cocos2dx v3.7 in JavaScript and have deployed it to the Android platform. I have submitted my apk to the Google Play Store and put the game in beta to test it out with my friends.

Some of them have told me their game just crashes mid way as they’re playing. I’m not exactly sure what is causing the crash but here are the native crash logs that Google Play Developer Console is showing me:
1

*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'samsung/nobleltebmc/nobleltebmc:5.1.1/LMY47X/N920W8VLU2AOK5:user/release-keys'
Revision: '9'
ABI: 'arm'
pid: 26580, tid: 26683, name: GLThread 10643  >>> rocky.race.game <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x3926
    r0 eee12840  r1 dc7ffb58  r2 ffffffff  r3 00000000
    r4 eee12840  r5 00003926  r6 eee1216c  r7 db7f3b90
    r8 db7f5000  r9 eec8827c  sl e21127cc  fp eee12148
    ip 00000000  sp f37f77c8  lr e1375978  pc e136d72c  cpsr 600f0010

backtrace:
    #00 pc 005d072c  /data/app/rocky.race.game-1/lib/arm/libcocos2djs.so

2

*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'samsung/t0ltevl/t0ltecan:4.4.2/KOT49H/I317MVLUDNH3:user/release-keys'
Revision: '10'
pid: 27163, tid: 27186, name: Thread-1478  >>> rocky.race.game <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 9999999a
    r0 63a66848  r1 675ded58  r2 ffffffff  r3 00000000
    r4 63a66848  r5 9999999a  r6 63a66174  r7 675435f8
    r8 67548c80  r9 63f62c7c  sl 610c67cc  fp 63a66150
    ip 00000000  sp 6261de78  lr 60329978  pc 6032172c  cpsr 60030010
    d0  0000000000000000  d1  0000000000000000
    d2  0000000000000000  d3  0000000000000000
    d4  4094980000000000  d5  437f80003d93dd98
    d6  43b440003f800000  d7  bf80000000000000
    d8  416fca0540000000  d9  416fca0555555555
    d10 0000000000000000  d11 0000000000000000
    d12 0000000000000000  d13 0000000000000000
    d14 0000000000000000  d15 0000000000000000
    d16 0000117459cf2211  d17 3ff0000000000000
    d18 bc4945bf7ffda060  d19 3fe62e4300000000
    d20 3fe62e42fefa39ef  d21 be205c610ca86c39
    d22 bf66bfcb262698a4  d23 3fecb695f172535c
    d24 bf77359d1d833c2a  d25 3ff0000000000000
    d26 be6209451ca00000  d27 3fba4b50746d6523
    d28 bf77359d1d833c27  d29 3f887d660e7c5249
    d30 be6209451ca7160a  d31 3f11551d246ea1cc
    scr 80000013

backtrace:
    #00  pc 005d072c  /data/app-lib/rocky.race.game-1/libcocos2djs.so
    #01  pc 005d8974  /data/app-lib/rocky.race.game-1/libcocos2djs.so

code around pc:
    6032170c e5915000 0a000005 e3a02000 e12fff33  
    6032171c e3a03000 e5843008 e584300c e8bd81f0  
    6032172c e5953000 e3c33eff e3c3300f e5933000  
    6032173c e5932000 e59219b4 e3510002 0a000025  
    6032174c e59229b4 e3520003 15d32008 0a000021  
    6032175c e3520000 08bd81f0 e3c524ff e1a01a25  
    6032176c e3c2260f e1a01a01 e1a071a2 e381193f  
    6032177c e38110a0 e207001f e3a06001 e1a02422  
    6032178c e1a00016 e791c102 e594802c e11c0000  
    6032179c 1a00000a e18c0000 e3580000 e7810102  
    603217ac 1a000012 e594201c e5941020 e1520001  
    603217bc 0a000018 e3855001 e4825004 e584201c  
    603217cc e3a02001 e5c322cb e3a03000 e5843008  
    603217dc e584300c e8bd81f0 e59322d4 e2422001  
    603217ec e3520001 83a02000 93a02001 eaffffd7  
    603217fc e0877008 e207201f e1a072a7 e1a06216  

code around lr:
    60329958 e1a00005 ebfff5f0 eaffffe8 e1a00005  
    60329968 ebffe9cd eaffffe5 e1a00005 ebffe63e  
    60329978 eaffffe2 e1a0000b e1a01005 e59d2004  
    60329988 ebfffe3a e59b0000 e1a01005 eb0da7a7  
    60329998 eaffffaf e59b3000 e593a154 e5933150  
    603299a8 e083a10a e2837004 e15a0007 03a09000  
    603299b8 15933004 01a08009 1593926c 15938268  
    603299c8 10889109 e15a0007 0a000020 e4980004  
    603299d8 e5903018 e5932000 e59219b4 e3510002  
    603299e8 0a000016 e59229b4 e3520003 15d33008  
    603299f8 0a000012 e3530000 0a00000d e1590008  
    60329a08 1afffff1 e1a02007 e2877004 e15a0007  
    60329a18 0a00000e e5b23004 e5d312c9 e3510000  
    60329a28 1afffff8 e593926c e5938268 e0889109  
    60329a38 eaffffe3 e1a01005 eb08922d eaffffee  
    60329a48 e59332d4 e2933000 13a03001 eaffffe8 

Does anyone have a clue as to what is causing these crashes?
Could it be that I’m adding the same child twice? Should I look for something in the libcocos2djs.so file?

Any help would be greatly appreciated. Thanks!

The devices these crashes occurred on are:

  1. Galaxy Note5 (nobleltebmc) Android 5.1
  2. Galaxy Note2 (t0ltecan) Android 4.4

On an iPhone and it also crashed at random times. Here are the logs from xCode 7.2 running on iPhone 4s iOS 9.2:

//
//  main.m
//  simulator
//
//  Copyright __MyCompanyName__ 2011. All rights reserved.
//

#import <UIKit/UIKit.h>

int main(int argc, char *argv[]) {
    
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, @"AppController"); //ERROR: Thread 1: EXC_BAD_ACCESS (code=1, adress=0x44)
    [pool release];
    return retVal;
}

and

Console: listening on  0.0.0.0 : 6050
Console: listening on  0.0.0.0 : 6060
------------------------------------------------
LOAD Js FILE: main.js
------------------------------------------------
warning: could not load any Objective-C class information from the dyld shared cache. This will significantly reduce the quality of type information available.
(lldb)

Just looking from the ios point of view the auto release pool looks like its trying to release an object that has already been freed hence why you get a bad access violation.

Ok so does this mean that somewhere in my code I am using release() on a sprite/object that is being automatically released?

It could be a number of reasons cocos uses automatic reference counting so something could be removed from a scene and then its trying to delete it I dont know try to see from what scene this crash happens in then just re check the code.

Hey @ChrisS91 ,

I’m still getting app crashes on iOS. It only happens when I deploy the app for distribution and not when it’s in debug mode.

Can you help me decipher these crash logs please:
Let me know if I should look at/share the Xcode crash log too.

1. Flurry Analytics Crash Report

Full Stack Trace:
0   RockyRaceGame-mobile                0x1008177a4 __Z22js_get_or_create_proxyIN7cocos2d26EventListenerTouchOneByOneEEP8js_proxyP9JSContextPT_ + 455296
1   RockyRaceGame-mobile                0x10081fb3c __Z22js_get_or_create_proxyIN7cocos2d26EventListenerTouchOneByOneEEP8js_proxyP9JSContextPT_ + 488984
2   RockyRaceGame-mobile                0x10086dac0 __ZN2JS12AutoGCRooter5traceEP8JSTracer + 317804
3   RockyRaceGame-mobile                0x100870c98 __ZN2JS12AutoGCRooter5traceEP8JSTracer + 330564
4   RockyRaceGame-mobile                0x1008711b4 __ZN2JS12AutoGCRooter5traceEP8JSTracer + 331872
5   RockyRaceGame-mobile                0x1008714c8 __ZN2JS12AutoGCRooter5traceEP8JSTracer + 332660
6   RockyRaceGame-mobile                0x100918f6c __ZN2JS12AutoGCRooter5traceEP8JSTracer + 1019416
7   RockyRaceGame-mobile                0x100914d1c __ZN2JS12AutoGCRooter5traceEP8JSTracer + 1002440
8   RockyRaceGame-mobile                0x10090de54 __ZN2JS12AutoGCRooter5traceEP8JSTracer + 974080
9   RockyRaceGame-mobile                0x100918f60 __ZN2JS12AutoGCRooter5traceEP8JSTracer + 1019404
10  RockyRaceGame-mobile                0x1009192a4 __ZN2JS12AutoGCRooter5traceEP8JSTracer + 1020240
11  RockyRaceGame-mobile                0x100840d40 __ZN2JS12AutoGCRooter5traceEP8JSTracer + 134124
12  RockyRaceGame-mobile                0x1007a32f8 __ZNSt3__112__hash_tableINS_17__hash_value_typeINS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEE12JSB_SIOEventEENS_22__unordered_map_hasherIS7_S9_NS_4hashIS7_EELb1EEENS_21__unordered_map_equalIS7_S9_NS_8equal_toIS7_EELb1EEENS5_IS9_EEE12__dealloc + 120448
13  RockyRaceGame-mobile                0x1007a3234 __ZNSt3__112__hash_tableINS_17__hash_value_typeINS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEE12JSB_SIOEventEENS_22__unordered_map_hasherIS7_S9_NS_4hashIS7_EELb1EEENS_21__unordered_map_equalIS7_S9_NS_8equal_toIS7_EELb1EEENS5_IS9_EEE12__dealloc + 120252
14  RockyRaceGame-mobile                0x10062cfd0 __Z22js_get_or_create_proxyIN7cocos2d12experimental2ui11VideoPlayerEEP8js_proxyP9JSContextPT_ + 16388
15  RockyRaceGame-mobile                0x100134340 -[AppController dealloc] + 984756
16  RockyRaceGame-mobile                0x1000e7334 -[AppController dealloc] + 669352
17  RockyRaceGame-mobile                0x100127774 -[AppController dealloc] + 932584
18  RockyRaceGame-mobile                0x100129250 -[AppController dealloc] + 939460
19  QuartzCore                          0x184eeb814 <redacted> + 40
20  QuartzCore                          0x184eeb6c8 <redacted> + 424
21  IOKit                               0x182a161e8 _IODispatchCalloutFromCFMessage + 372
22  CoreFoundation                      0x1827431f8 <redacted> + 180
23  CoreFoundation                      0x182759634 <redacted> + 56
24  CoreFoundation                      0x182758d6c <redacted> + 436
25  CoreFoundation                      0x182756ac4 <redacted> + 1800
26  CoreFoundation                      0x182685680 _CFRunLoopRunSpecific + 384
27  GraphicsServices                    0x183b94088 _GSEventRunModal + 180
28  UIKit                               0x1874fcd90 _UIApplicationMain + 204
29  RockyRaceGame-mobile                0x100041844 -[RootViewController dealloc] + 1440
30  ???                                 0x1822268b8 0x0 + 0

2.Another Flurry Analytics Crash Report

Full Stack Trace:
0   RockyRaceGame-mobile                0x00817e10 __ZN2js2gc14MarkObjectRootEP8JSTracerPP8JSObjectPKc + 39
1   RockyRaceGame-mobile                0x0081dd17 __ZN2js2gc9GCRuntime11markRuntimeEP8JSTracerb + 322
2   RockyRaceGame-mobile                0x0085ac5d __ZN2js2gc9GCRuntime14beginMarkPhaseEN2JS8gcreason6ReasonE + 1824
3   RockyRaceGame-mobile                0x0085d1ef __ZN2js2gc9GCRuntime23incrementalCollectSliceExN2JS8gcreason6ReasonENS_18JSGCInvocationKindE + 506
4   RockyRaceGame-mobile                0x0085d60b __ZN2js2gc9GCRuntime7gcCycleEbxNS_18JSGCInvocationKindEN2JS8gcreason6ReasonE + 174
5   RockyRaceGame-mobile                0x0085d83b __ZN2js2gc9GCRuntime7collectEbxNS_18JSGCInvocationKindEN2JS8gcreason6ReasonE + 178
6   RockyRaceGame-mobile                0x0085d953 __ZN2js2gc10GCIfNeededEP9JSContext + 66
7   RockyRaceGame-mobile                0x008d71dd __ZN2js6InvokeEP9JSContextN2JS8CallArgsENS_14MaybeConstructE + 416
8   RockyRaceGame-mobile                0x008d4b3b __ZL9InterpretP9JSContextRN2js8RunStateE + 19762
9   RockyRaceGame-mobile                0x008cfde9 __ZN2js9RunScriptEP9JSContextRNS_8RunStateE + 188
10  RockyRaceGame-mobile                0x008d71d5 __ZN2js6InvokeEP9JSContextN2JS8CallArgsENS_14MaybeConstructE + 408
11  RockyRaceGame-mobile                0x008d741d __ZN2js6InvokeEP9JSContextRKN2JS5ValueES5_jPS4_NS2_13MutableHandleIS3_EE + 336
12  RockyRaceGame-mobile                0x00835c57 __Z19JS_CallFunctionNameP9JSContextN2JS6HandleIP8JSObjectEEPKcRKNS1_16HandleValueArrayENS1_13MutableHandleINS1_5ValueEEE + 242
13  RockyRaceGame-mobile                0x007c28cb __ZN13ScriptingCore24executeFunctionWithOwnerEN2JS5ValueEPKcRKNS0_16HandleValueArrayENS0_13MutableHandleIS1_EE + 202
14  RockyRaceGame-mobile                0x007c27f3 __ZN13ScriptingCore24executeFunctionWithOwnerEN2JS5ValueEPKcjPS1_ + 66
15  RockyRaceGame-mobile                0x0065b8b3 __ZN17JSScheduleWrapper6updateEf + 78
16  RockyRaceGame-mobile                0x001aa731 __ZNKSt3__18functionIFvfEEclEf + 20
17  RockyRaceGame-mobile                0x0015ca6b __ZN7cocos2d9Scheduler6updateEf + 194
18  RockyRaceGame-mobile                0x0019d0ed __ZN7cocos2d8Director9drawSceneEv + 36
19  RockyRaceGame-mobile                0x0019ea5f __ZN7cocos2d19DisplayLinkDirector8mainLoopEv + 54
20  libglInterpose.dylib                0x013509a1 -[DYDisplayLinkInterposer forwardDisplayLinkCallback:] + 272
21  QuartzCore                          0x28a707c3 <redacted> + 106
22  QuartzCore                          0x28a7060f <redacted> + 594
23  IOMobileFramebuffer                 0x2815b57b <redacted> + 86
24  IOKit                               0x26a3a3e9 _IODispatchCalloutFromCFMessage + 256
25  CoreFoundation                      0x2679dae9 <redacted> + 132
26  CoreFoundation                      0x267afe43 <redacted> + 34
27  CoreFoundation                      0x267af557 <redacted> + 342
28  CoreFoundation                      0x267ad969 <redacted> + 1688
29  CoreFoundation                      0x26700bf9 _CFRunLoopRunSpecific + 520
30  CoreFoundation                      0x267009e5 _CFRunLoopRunInMode + 108
31  GraphicsServices                    0x2794cac9 _GSEventRunModal + 160
32  UIKit                               0x2a990ba1 _UIApplicationMain + 144
33  RockyRaceGame-mobile                0x000b42cf _main + 74
34  libdyld.dylib                       0x263af873 <redacted> + 2

If you experience a problem only in distribution and not in debug mode it could be due to the higher optimization level of the distribution build. In the build settings of your target in Xcode look for the optimization level setting and set the release/distribution one to ‘None’.

I tried that but it still crashed :frowning:

Any other ideas? Could it be a bug in Cocos2d-x v3.7?

I have a few suggestions for you…

Another option is to set ‘generate debug symbols’ to true and ‘strip debug symbols’ to false for the release mode and build your app in release mode. Release mode and distribution have the same compiler options. So if you test your app in release mode you should be able to reproduce the error and get a better stack trace.

I see in your first crash report that it happens in a touch listener. Make sure your listeners are allocated and deallocated only once. How do you add and remove your touchOneByOne listeners?

Another thing to test is if your app survives a memory warning. This can be done in the iPhone simulator (it’s a option in the menu).

I don’t want to bring bad news, but things like this tend to be your own fault.

1 Like

I think you are right.

The only section in my cocos project that uses EventListener.TouchOneByOne is the code I used from this Cocos Forum Post which I used to avoid multiple touches of ccui.Buttons. I used this method/function in 2 difference scenes in my project.

EDIT: I am making a mobile racing game and I always use cc.eventManager.removeAllListeners(); at the end of each race.

UPDATE: I tried commenting out the part of the code that uses touchOneByOne listeners but the game still crashed. Need to do more debugging. Don’t worry about bringing bad news, if it’s my fault then I just want to get to the bottom of this. I really appreciate all your help and suggestions.

@araker
I was reading this: Understanding and Analyzing iOS Application Crash Reports and saw this:

Bad Memory Access [EXC_BAD_ACCESS // SIGSEGV // SIGBUS]

The process attempted to access invalid memory. The Exception Subtype field contains a kern_return_t describing error. The Exception Sub-code (the value following the exception subtype) lists the bad memory address that was accessed.

If objc_msgSend or objc_release is near the top of the Backtrace for the crashed thread, the process may have attempted to message a deallocated object. You should profile the application with the Zombies instrument to better understand the conditions of this crash.

So I made a Zombies crash report but not sure how to read it exactly. I will do some more research online but do you have any experience with this? Here is a link to the Zombie Trace Report

When I run the project in Xcode on my iOS device, it crashes but Xcode doesn’t report any bugs.

I can’t open the stack trace, I get a error message that the trace is malformed. Normally when you debug with zombies enabled you get a message that the system tries to deallocate a already deallocated instance. But the app shouldn’t crash in that case. See also this link for more information. Are you sure you’re using the correct settings?

If enabling NSZombies doesn’t give you any answers, another option is to override the dealloc method of all your classes and put a log message in it. You need to enable logging for release mode, this is done in the project build settings in the ‘preprocessor marcos’, remove the NDEBUG flag and insert the COCOS2D_DEBUG = 1 flag for the release settings.

@araker
After some more debugging I am seeing that before an EXC_CRASH (SIGSEGV) crash there is always an EXC_RESOURCE crash report happening first. I am making a racing game and the crash always happens in the third time racing. After finishing 2 races, I click play again and the crash happens at a random time during that “race”.

Here is a link to the EXC_RESOURCE Crash Log. Please feel free to leave a comment where I should look/focus on.

Much appreciated!

@efares, I don’t have any experience with EXC_RESOURCE. From this topic I understand that it is triggered when a background thread is getting a wake-up signal too often. Though in your report this isn’t the case (Observed 0/sec over 300 secs). So I’m wondering if this is even a real issue.

I see you’re using v3.7, you could try to update to 3.10, since there have been some changes to JSB’s memory handling functionality.