8

I recently I came across an error that I cannot understand. The game I'm developing using Cocos2D just freezes at a certain random point -- it gets a SIGSTOP -- and I cannot find the reason. What tool can I use (and how do I use it) to find out where the error occurs and what's causing it?

Monolo
  • 18,205
  • 17
  • 69
  • 103
Allan
  • 117
  • 5
  • 2
    Hit the pause button in your debugger and see if it gives you the location of possibly a deadlock. – Jeremy Apr 19 '13 at 20:09

2 Answers2

8

Jeremy's suggestion to stop in the debugger is a good one.

There's a really quick way to investigate a freeze (or any performance issue), especially when it's not easy to reproduce. You have to have a terminal handy (so you'll need to be running in the iOS simulator or on Mac OS X, not on an iOS device).

When the hang occurs pop over to a terminal and run:

sample YourProgramName

(If there are spaces in your program name wrap that in quotes like sample "My Awesome Game".) The output of sample is a log showing where your program is spending time, and if your program is actually hung, it will be pretty obvious which functions are stuck.

Community
  • 1
  • 1
Aaron Golden
  • 7,092
  • 1
  • 25
  • 31
  • Oh, Thank you so much for the answer, I'll try this. I'm still trying to reproduce the error, but it Occur When again, from what you said. Again, thank you for the answer! – Allan Apr 19 '13 at 20:51
  • 1
    I done what you say and I found the problem. There is a loop in one of my methods, but the weird is the debbuger not pointed to it when I paused and this made ​​it difficult to find the error. Thank you for everything! – Allan Apr 20 '13 at 16:16
1

I disagree with Aaron Golden's answer above as running on a device is extremely useful in order to have a real-case scenario of where the app freezes. The simulator has more memory and does not reproduce the hardware of the device in an accurate way (for example, the frame rate is in certain cases lower).

"Obviously", you need to connect your device (with a developer profile) on Xcode and look at the console terminal to look for traces that user @AaronGolden suggested.

If those are not enough you might want to enable a general exception breakpoint in Xcode to capture more of the stacktrace messages.

When I started learning Cocos2D my app often frooze. This is a list of common causes:

  • I wasn't using sprite sheets and hence the frame rate was dropping drammatically
  • I was using too much memory (too many high-definition sprites. Have a look at TexturePacker and use pvr.ccz or pvr.gz format; it cuts memory allocation in half)

Use instruments to profile your app for memory warnings (for example, look at allocation instruments and look for memory warnings).

Community
  • 1
  • 1
mm24
  • 9,280
  • 12
  • 75
  • 170
  • Why did you put my name in scare quotes? Anyway, the issue seems to be that OP can't reproduce the issue on demand, and it can be frustrating running with instruments every time just in case you happen to hit the bug *this* time. That's why I said just be ready to switch to the terminal and run sample. If OP *can* reproduce the issue reliably then Instruments is the right way to go, but why did you suggest the allocations tool? Surely the time profilers is the most applicable tool for a generic hang/slowness issue. – Aaron Golden Apr 19 '13 at 20:45
  • I am doing as you say, use texture packer to all my sprites (pvr.ccz). I'll try what you mentioned! Thanks for the reply, really appreciate it. – Allan Apr 19 '13 at 21:00
  • If the App freezes it might be due to some "system overload" and thought that memory allocation could affect, but might be wrong – mm24 Apr 19 '13 at 21:00
  • But there is no frame rate drop. – Allan Apr 19 '13 at 21:06
  • Yeah sorry man, I am a newbie as well, so listen to what people like @AaronGolden say in this forum. They have much more knoweldge and experience :), sorry for misleading. – mm24 Apr 19 '13 at 21:08
  • Thank you mm24, certainly I'll use your tips too! – Allan Apr 20 '13 at 16:17