Debug View Crash

Topics: Developer Forum
Feb 16, 2011 at 7:39 PM

I've had this issue since I first started using Farseer - game crashes with an out of bounds exception here:

 

public void DrawPolygon(Vector2[] vertices, int count, Color color)
        {
            for (int i = 0; i < count - 1; i++)
            {
                _vertsLines[_lineCount * 2].Position = new Vector3(vertices[i], -0.1f);
                _vertsLines[_lineCount * 2].Color = color;
                _vertsLines[_lineCount * 2 + 1].Position = new Vector3(vertices[i + 1], -0.1f);
                _vertsLines[_lineCount * 2 + 1].Color = color;
                _lineCount++;
            }

            _vertsLines[_lineCount * 2].Position = new Vector3(vertices[count - 1], -0.1f);
            _vertsLines[_lineCount * 2].Color = color;
            _vertsLines[_lineCount * 2 + 1].Position = new Vector3(vertices[0], -0.1f);
            _vertsLines[_lineCount * 2 + 1].Color = color;
            _lineCount++;
        }

 

 

Trouble is, it only happens after the game's been running for 5-10 minutes, so I've never really looked into it since most of my testing is a couple of minutes, tops.

I'm not actually doing anything with the Debug View at the time (it's doesn't need to be drawing for the crash to occur; Draw() is only called if it's toggled on, and the crash occurs even if not:#

 	// Draw Debug Info?
        if (bDrawDebugInfo)
        {
            _debugViewManager.Draw();
        }

 

Because it's a crash I only encounter once every few weeks, I tend to forget about it on the assumption that I can easily comment out the debug view manager should need be, but thought I might post here this time in the hopes that it happens to someone else, or you might be interested?

For the record, this is all I'm doing with the debugView, nothing more than initialise and draw:

 

	public DebugViewManager()
        {
            _debugView = new DebugViewXNA(_world);
            
        }

        public void LoadContent()
        {
            _debugView.LoadContent(_graphicsDeviceManager.GraphicsDevice, content);
            
        }

        public void Draw()
        {
            _debugView.RenderDebugData(ref OurUniverse.Instance._camera.Projection, ref  OurUniverse.Instance._camera.View);
           
        }

 

 

It happened on the (old?) 3.0 version, I'm now using 3.2 and it's still happening. Any ideas?

Coordinator
Feb 17, 2011 at 1:34 AM

I see the problem there. If any of the draw methods gets called on each draw/update, it will increase the lineCount field - it is only reset to 0 when RenderDebugData() is called. If you deactivate the drawing, it will eventually reach a number higher than the size of the array and give the exception.

I will copy this to an issue.

Coordinator
Feb 17, 2011 at 1:34 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Feb 17, 2011 at 12:01 PM

Yaaay! I'm extremely pleased it wasn't just something stupid I was doing ;)