- Home /
The question is answered, right answer was accepted
Simple Code that crashes Unity for some strange reason!
The beggining of the code below is my constructor, the end is the function it calls.
this.storage = InititalizeStorage(_colsAvailable, _rowsAvailable);
}
private InventorySlot[] InititalizeStorage(int cols, int rows)//, GUIStyle _style)
{
InventorySlot[] storageSlots = new InventorySlot[cols * rows];
for(int i = 0; i < storageSlots.Length; i++)
storageSlots[i] = new InventorySlot(null);//, _style);
return storageSlots;
}
When InitializedStorage is called from another function in start it works fine. So my only question is why does unity say "Fatal Error! Allocating memory when not allowed to"?
Hey, can we see your InventorySlot Struct (or class)?
What line is the fatal error occuring on? What's the full debug message?
The code works fine on my computer, with large ints as colums and rows, using a struct with a constructor.
I cant acess my computer, it defragmenting, but I can type it by hand... something says it wont help.` public class InventorySlot {
public Item item; public bool empty;
public InventorySlot (Item _item) { this.Item = _item; this.empty = false;
if(_item == null)
this.empty = true;
}`
Answer by ffxz7ff · Feb 05, 2014 at 01:55 AM
Not sure about the Fatal Error, but it could have to do with the fact that
storage[i] = new InventorySlot(null);//, _style);
is probably supposed to be
storageSlots[i] = new InventorySlot(null);
$$anonymous$$y bad. It was a typo. Thats what the code actually is, and ive edited above. I wish it was that simple of a fix. Thanks!
Follow this Question
Related Questions
How can I reset unity 3d? 2 Answers
Fatal Error! 0 Answers
Fatal error in gc: too many threads 1 Answer