Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging methods for finding the location and error that's causing a game to freeze

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?

like image 755
Allan Avatar asked Apr 19 '13 19:04

Allan


People also ask

How do you debug a crashed application?

You can use the stack trace available in the report details if you are using Play Console or the output of the logcat tool. If you don't have a stack trace available, you should locally reproduce the crash, either by manually testing the app or by reaching out to affected users, and reproduce it while using logcat.

What causes games to freeze and crash?

Here is a list of main reasons that may cause your games to freeze in Windows 10/8/7: High CPU or RAM Memory usage. Graphics card low performance. Low Internet speed, unstable network connection.

What Causes program to freeze?

This can be caused by too many programs running at once, not enough memory (RAM), or memory fragmentation, slow hardware access (especially to remote devices), slow system APIs, etc. It can also be caused by hidden programs which were installed surreptitiously, such as spyware.

How you would figure out an error without debugger?

But how to debug a program without a debugger? One possible approach which I know is simply putting print statements in your code wherever you want to check for the problems.


2 Answers

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.

like image 72
Aaron Golden Avatar answered Oct 04 '22 16:10

Aaron Golden


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).

like image 23
mm24 Avatar answered Oct 04 '22 15:10

mm24