This project has moved and is read-only. For the latest updates, please go here.

Explosion.cs crash on MaxShapes Array

May 10, 2012 at 8:10 PM

I'm getting a crash if Explosion.cs has more than MaxShapes in its radius. 

I'm using the latest version. It seems to be that it's just able to go outside the bounds of the array. Is there a known fix for this? Presumably it'd be sensible to tell it to ignore certain types of Fixture, etc, but that won't override the core problem.

I'm using the latest version...


May 17, 2012 at 2:41 PM
Edited May 17, 2012 at 2:50 PM

Hi, I'm the one who poorly wrote the explosion.cs (sorry for the error, indeed your error is because it's going out of bounds of the shapes' array size)

Just increase the MaxShapes value number in the source code. It is 100 by default, but you can set it to the number you want.

For avoiding having this error in the future, you can change the line that says:

shapes[shapeCount++] = fixture;


if(shapeCount < MaxShapes)
    shapes[shapeCount++] = fixture;

But then, if the number of shapes affected by the explosion is above the MaxShapes value, some shapes will not be affected by the explosion. So probably increasing the MaxShapes number should be the best option.

Just curious, how many shapes are being affected by the explosions in your game? Does it performs well? I'm asking that because the explosion.cs casts a lot of raycasts in order to make it look somehow realistic (in my game looks quite nice), but I'm not sure how it would perform in +100 affected shapes. Anyway, I think the code still has room for improvement (specifically by avoiding allocating memory each time an explosion is called), but so far it works well.

May 17, 2012 at 4:23 PM
Edited May 17, 2012 at 4:24 PM

Yeah, limiting it is exactly what I did in the end. Was waiting to see if there's a more sensible approach.

Turns out the problem was mainly because the radius I was setting was preposterously large, and there was a bug in the draw code that made it seem like it was a reasonable-sized explosion. So once I'd toned that down, I was rarely getting more than 15-20 bodies.

I can't remember off hand, but I think I also added some stuff to filter out non-Dynamic objects. Or was that in already? I have a feeling it was picking up statics too... ??

Regardless- thanks. The code works great, and saved me a huge job :)