Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views

Segmentation Fault fixed

Sign in to follow this  


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!

Sign in to follow this  


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!