• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by ShadowM8 · Aug 21, 2012 at 08:52 PM · crashheap

Too many heap sections

Hi all.

I've ran into an crash to desktop with the following error:

 Fatal error in gc Too many heap sections

I've implemented a very textbook A* path finding that worked just fine until I began to do some very basic refactoring. After hours of tracking down what changed causes the crash I narrowed it down to a single line that when changed would cause Unity to crash to desktop.

This is working code:

 float nCost = node.IsDiagnal(current) ? 7 : 5;

If I change this line to something as simple this I get the crash:

 float nCost = node.IsDiagnal(current) ? 50 / 20 : 5;

In fact even if I replace the 7 with a float variable that has been previously initialized, lets say in `Start()`, with an arithmetic operation like `float value = 50 / 20;` it will still crash!

I'm completely lost here! Any help would be greatly appreciated!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Exxon · Apr 02, 2013 at 11:42 AM

I encountered the exact same problem when using my own A* path finding.

You can check the GC memory usage with this

 print (System.GC.GetTotalMemory(true));


For me it came down to the amount of data that was being stored in each node of the grid. When using a large grid or one with high resolution it would throw the error Too many heaps. I was storing a reference to the parent node (class) on every node and writing over the data when searching. I was also using 2 grids on top of each other, one with as low resolution as possible for full grid searches, and a second with high resolution for short searches around units etc.

To fix the problem I did 2 things... 1 - I made a separate class for the search nodes with all the needed data for the search and removed that data from the grid so that the grid nodes only contained the bare minimum.

 [System.Serializable]
 public stuct s_AStar_Node
 {
     public bool isValid;         // is this node vaild
 
     public Vector3 nodePos;      // the position of the node in the world space
     
     public int indexX;            // the x index of this node in the grid
     public int indexY;            // the y index of this node in the grid
 }

Then the search node I added the parent node reference aswell as the f, g, and h values

 public class s_AStar_SearchNode
 {
     public bool isValid;
     
     public int indexX;
     public int indexY;
     
     public s_AStar_SearchNode parentNode;
     
     public int f;
     public int g;
     public int h;
 }

One thing to take note of here is that the search node doesn't have the world position as I use the index from the search node to pull the grid node for the final path.

2 - Removed my small (high resolution) grid. After doing some testing I found that I could get away without doing fine path finding around moving unit which is what its was intended for. Also my game is on mobile devices so I couldn't afford a hole lot of memory for path finding.

Hope this helps for anyone else that is doing this sort of thing.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity Web Player keeps crashing my browser 9 Answers

Playerprefs save player position 3 Answers

load level problem when building to ipad 2 Answers

Crash To Desktop 100% reproducable. 0 Answers

hang in unity splash screen... 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges