views:

146

answers:

6

Hi everyone

I have built my first game using Cocos2D. It worked fine on the simulator. But when it runs on the actual iPhone, it crashes. I don know why. Thought it was memory leaks, so i tried to detect, but no leaks found. I tried to increase and decrease frame rate, neither both succeeded. Anyone experienced please help me out. I am really stressed now. If anyone had the same issue please share with me your opinion.

Yours thanksfully.

A: 

Sorry, but you need to specify more details. How does it crash? What does the error log say? One thing you might look into is the amount of memory, your game consumes. If it uses more than 64 MB on the actual device, the OS will very likely just terminate it. In the simulator on the other hand, your app might use lots more memory without a problem.

Mo
Thanks for your reply, the error says nothing. It is totally fine when running on the simulator. My file is 15MB only. Is it too big ? there are 3 parts in the game, introduction, game play, and game result. It starts to crash at the game play. It just blacks out stops running the game. This only happens in the actual iPhone. I tried a lot of ways, like using AtlasSprite for animation instead of Sprite, reduce the amount of images. I removeChild whenever it is not needed so the images won't overlap each other. I have no ideas now. Really frustrated.
Rocker
A: 

I agree with Dominic - we definitely need more information to be able to help you - do you have the output from the console or the stack from the debugger?

Also, while memory leaks are a Bad Thing, they rarely lead to crashes directly. They will increase the amount of memory used by your app so if you're memory intensive then you might get a problem but they're not the first place I'd look to try to debug this.

Try running the app in Instruments and watch the memory usage graph - then not only can you see the total that your app is using but you can get an idea of which sections of your app use the most and can focus your efforts in reducing it.

Sam

deanWombourne
I have tried everything that I know to reduce the memory usage. Hmm is it because I created so many classes? I have 8 classes in total to build this game.
Rocker
Nope, the number of classes you have isn't an issue (and 8 is not many!) - it's more the number of instances of each class you have made - if the problem is memory related at all!What's your peak memory usage in MB?
deanWombourne
Hmm, Can I ask you one thing? what are the common reasons for the game to crash in the iPhone besides the memory problem. What i am doing now, is I removed all the AtlasSprite and Sprite, even then timer, text, last time there are 4 colours for the image, now I remove 3, left one , and i tried to look over the CPU sampler, it jumped up so high when I started to play the game. I don know why now, is it because my images are too big?
Rocker
OK, without a stack trace and no errors to work from the thing I would try now is to build a new copy of the app, trying on the phone each time you make a change. Eventually, it will stop working - that's where your bug is! I think that you're probably barking up the wrong tree if you've removed all your stuff and it's still crashing. (And the if you're using openGL, you should expect the CPU graph to be high!)
deanWombourne
A: 

What's your call stack look like?

jessecurry
A: 

I have found tools like Instruments and NSZombieEnabled to be very helpful in tracking down issues such as these.

fbrereto
A: 

Without more information, I would try the following steps:

Delete the app from the device and simulator (using the tap-and-hold technique to make your icons jiggle) and reinstall it. Sometimes a setting (or lack of a setting) in the user defaults will cause a crash, and those don't get wiped out unless you delete and re-run your app.

Also try the "simulate memory warning" option in the simulator and see if that gets it to crash.

Frank Schmitt
+1  A: 

I've run into similar issues (I also use Cocos, but I don't think this is Cocos specific). The best thing to do is plug-in your iPhone and watch the stacktrace when it crashes (or retrieve the stacktrace after the fact)

This happened to me a lot because the resources between the iPhone and the simulator were not in sync; in other words, some how resources would be available to the simulator (eg: images) but those same resources were not transferred to the iPhone for whatever reason. Sometimes, if I ran 'clean' on the simulator, I would observe the same issue.

It's extremely frustrating to debug these types of issues, but you'll get used to it.

Eric Farraro