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

Bug in DrawingHelper.CreateLineTexture(...)

Topics: Developer Forum
Dec 12, 2008 at 5:20 PM
Edited Dec 12, 2008 at 5:20 PM
I know this is not directly related to the physics engine, but I thought it might interest you that it seems there's a bug in the DrawingHelper.CreateLineTexture(GraphicsDevice graphicsDevice, int lineThickness, Color color) with regards to line thickness. The function creates a Color array, changes the color of the 2 first pixels to transparent white, but then imediately overwrites these 2 values in the "for" loop. Take a look.
            int count = 2 * (lineThickness + 2);
            Color[] colorArray = new Color[count];
            colorArray[0] = Color.TransparentWhite; // A
            colorArray[1] = Color.TransparentWhite; // B

            for (int i = 0; i < count; i++) // This for loop starts at the very first pixel. It should start at pixel 3 (Which has the index '2')
                colorArray[i] = color;

            colorArray[count - 2] = Color.TransparentWhite;
            colorArray[count - 1] = Color.TransparentWhite;
            return texture2D;
A quick fix is to move lines A and B beneath the 'for' loop. But really, the 'for' loop should changed to: for (int i = 2; i < count - 2; i++) - Then, all is well. :-)

I noticed this, because I use the drawing tools in my own hobby projects, and I just couldn't understand why my lines didn't have the correct width. It was always 1 pixel wider.

Thanks for a great engine, and for some great tools to draw primitives in XNA. :-)

Best regards
Dec 12, 2008 at 5:53 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.