Too many heap sections

Hi all,

I’m refactoring some existing C# code and all of the sudden I get:

“Fatal error in gc
Too many heap sections”

Unity crashes to desktop…

I have no idea were to begin to track this down, any ideas?

All I did in the refactoring is created a public Vector2 variable that gets initialized in the Start function.
Then I used it to replaced some redundant code in that class which was basically doing a basic arithmetic calculation.

In fact I can reproduce the crash by editing a single line:

This works:

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

This crashes if I replace the numbers with the aforementioned Vector2 variable:

float nCost = node.IsDiagnal(current) ? myVec2.x : myVec2.y;

Thoughts?

Thanks!

I believe I saw this message a few times. Restarting Unity editor should magically remove it.

No luck!
I even updated to 3.5.5 with a hopes it will magically resolve itself.

After further digging I was able to track it down even more.
A very simplified version of my code looks like this:

private float valueA;
private float valueB;

void Update()
{
    float nCost = node.IsDiagnal(current) ? valueA : valueB;
}

void Start()
{
    valueA = 5;
    valueB = 7;
}

This works, however if I replace the Start code to something like:

void Start()
{
    valueA = 50 / 20;
    valueB = 7;
}

Then I get the error and crash!

I’m completely lost here!