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
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?
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.
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.
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’.
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.
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.
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.
@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.