Segmentation Fault fixed

Published March 01, 2017
Advertisement

After many hours debugging I finally fixed it!

There are many reasons for a segmentation fault, but for mine I will try to list what I did to help those who face similar problems.

First of all I was building my game for an Android device. In order to debug, make sure you have debugging settings turned on on your phone (under developer settings).

Then, play your game until the crash happens. After, go to the sdk folder on your computer and find the program-tools folder. Open the command prompt (I was using Windows) CMD, and set the 'cd' current directory, to that folder.

Then type: adb logcat>myLogFile.txt

and then press enter. the text file can be named anything. Within the file is a huge chunk of data. To save scrolling, you can use ctrl F to search for Unity, which singles out all the Unity messages.

Eventually you will find a crash log with some small details (but not much).

If it is a segmentation fault, then the chances are your game isn't optimised enough for the device.

Have a look at the following:

Are you using foreach loops in start functions? If yes, take them out. Perhaps manually add the items in the inspector or use a for loop.

Are you duplicating anything? Such as having the same audio source over two scripts etc.

Are you using GetComponent a lot? If so, then cache them at the start instead. And use that reference instead of creating new GetComponents every time.

In coroutines, are you using Yield wait return new WaitForSeconds() ? If yes, then cache the WaitForSeconds up the top as well. Then in the coroutine you can write: Yield wait return _variableName;

If you have strings that stack together, consider using a Stringbuilder instead.


These are just some of the things that I did to keep the memory consumption down. Hopefully you all find this knowledge useful!

0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement
Advertisement