I have quite an annoying problem that I can't seem to get around. I believe the issue is caused by some threads I have set up which create rather large physics bodies from a custom texture. These threads are being ran every 1 and a half seconds and being
added to the physics world as soon as they are completed.
However after running the program for a time it crashes after what seems a random time. I get an error dialogue box at various different lines of code in DynamicTree.cs
What does this class do? I am not sure what is causing the crashes because I am always waiting for the physics bodies to be finished generating before adding them to the world and then after that it is business as usual.
If anyone has any input I would be very grateful, thanks!
An example of one of the crashes would be "A first chance exception of type 'System.IndexOutOfRangeException' occurred in FarseerPhysicsXNA.dll" in "Allocate Node()" n DynamicTree.cs, on the lines
//_freeList AT THE MOMENT OF CRASH IS -1
// Expand the node pool as needed.
if (_freeList == NullNode)
//ERROR IS ON THIS LINE
Debug.Assert(_nodeCount == _nodeCapacity);
// The free list is empty. Rebuild a bigger pool.
DynamicTreeNode oldNodes = _nodes;
_nodeCapacity *= 2;
_nodes = new DynamicTreeNode[_nodeCapacity];
Array.Copy(oldNodes, _nodes, _nodeCount);
// Build a linked list for the free list. The parent
// pointer becomes the "next" pointer.
for (int i = _nodeCount; i < _nodeCapacity - 1; ++i)
_nodes[i].ParentOrNext = i + 1;
_nodes[_nodeCapacity - 1].ParentOrNext = NullNode;
_freeList = _nodeCount;