I've been writing a flash game for 300 hours, and wrapping it up now.
I've solved all the errors except for one.
Unfortunately this is a fatal error I cannot solve, nor can anyone else.
When attempting to destroy bodies (which works fine all the time), the Box2D gives the following mystifying result.
Cannot access a property of a null reference - body.[b2Body].
Somehow, although the body clearly exists, it can't be destroyed since it is 'null'.
The body also has no texture, and no way to identify or distinguish it among others.
It has no width, no height. There is NO way to tell what this body is or why it brings the game to a halt when you destroy it.
I added the line, "if (body != null) and it still produces the null error above.
I tried adding textures to all bodies and it still produces the error.
I tried adding code inside b2World to make it 'null' after it's destroyed, but this doesn't work.
I tried iterating or getting information about the instance name, or the body or anything, but nothing.
The destruction happens by inserting items in an array, then deleting them all during the update() function.
I have not experienced this problem the first 200 hours of programming.
The glitch appears to happen when an exploding ball explodes, and the shrapnel hits the character.
I check for all types of collisions.
My only theory is that somehow after collision the object is being added to the DestroyList vector twice.
So Box2D is trying to destroy the object which has already been destroyed.
Even though I've placed safeguards so that objects can't be duplicated in the same array, and
all objects are spliced out when they are destroyed.
There is no point or way to post other code, it is 120 pages.
But this is the destroy code. The error always happens on Destroy.destroy().
private function destroyBodies():void
{
var k = Destructor.DestroyList.length;
while (k--)
{
var Destroying = Destructor.DestroyList[k];
if(Destroying!= null && Destroying.parent != null)
{
Destroying.parent.removeChild(Destroying);
}
Destroying.destroy();
}
Destructor.DestroyList.length = 0;
}
I've solved all the errors except for one.
Unfortunately this is a fatal error I cannot solve, nor can anyone else.
When attempting to destroy bodies (which works fine all the time), the Box2D gives the following mystifying result.
Cannot access a property of a null reference - body.[b2Body].
Somehow, although the body clearly exists, it can't be destroyed since it is 'null'.
The body also has no texture, and no way to identify or distinguish it among others.
It has no width, no height. There is NO way to tell what this body is or why it brings the game to a halt when you destroy it.
I added the line, "if (body != null) and it still produces the null error above.
I tried adding textures to all bodies and it still produces the error.
I tried adding code inside b2World to make it 'null' after it's destroyed, but this doesn't work.
I tried iterating or getting information about the instance name, or the body or anything, but nothing.
The destruction happens by inserting items in an array, then deleting them all during the update() function.
I have not experienced this problem the first 200 hours of programming.
The glitch appears to happen when an exploding ball explodes, and the shrapnel hits the character.
I check for all types of collisions.
My only theory is that somehow after collision the object is being added to the DestroyList vector twice.
So Box2D is trying to destroy the object which has already been destroyed.
Even though I've placed safeguards so that objects can't be duplicated in the same array, and
all objects are spliced out when they are destroyed.
There is no point or way to post other code, it is 120 pages.
But this is the destroy code. The error always happens on Destroy.destroy().
private function destroyBodies():void
{
var k = Destructor.DestroyList.length;
while (k--)
{
var Destroying = Destructor.DestroyList[k];
if(Destroying!= null && Destroying.parent != null)
{
Destroying.parent.removeChild(Destroying);
}
Destroying.destroy();
}
Destructor.DestroyList.length = 0;
}