RE: Exception raised when drawing many circles

Hello Olivier,
|>As you can see in the sample code that I have posted, I make absolutely no
|>call to IDirect3DDevice::DrawIndexedPrimitives(). The only drawing call that
|>I make is to Line.DrawTransform(), and it is INSIDE this function that the

I know you did not call IDirect3DDevice::DrawIndexedPrimitives() in code. actually, IDirect3DDevice::DrawIndexedPrimitives() is used inside the
ID3DXLine::DrawTransform (in mdx, it is Line.DrawTransform()).

|>problem occurs. The vertex buffer is not mine but the one used internally by
|>the class Line (there is no vertex buffer in my sample code).

I am not sure if the code is written by you, but in the code you post to me, I can find following lines:
private void SetupBuffersRH()
int count = 144;
double radius = 1.0;
double angle;

this.polyline = new Vector3[count + 1];
this.polylineTra = new Vector3[count + 1];

for (int i = 0; i <= count; i++)
angle = i * 2.0 * Math.PI / count;
this.polyline[i] = new Vector3(
(float)(radius * Math.Cos(angle)),
(float)(radius * Math.Sin(angle)),

// and in your render code, you used following code to make the vertex buffer
for (int i = 0; i < circleCount; i++)
float trax = (float)(10.0 * rnd.NextDouble() - 5.0);
float tray = (float)(10.0 * rnd.NextDouble() - 5.0);

for (int j = 0; j < this.polyline.Length; j++)
this.polylineTra[j] = this.polyline[j];
this.polylineTra[j].X += trax;
this.polylineTra[j].Y += tray;

this.liner.DrawTransform(this.polylineTra, pv, Color.White);


>From the code above, you created a buffer with 145 vertices and then draw lines with these vertices. When dx consumes the last 4 vertices, it raises the problem.

|>My opinion is that there is a bug in Line.DrawTransform() (or
|>ID3DXLine::DrawTransform) when the length of the array of vertices is too
|>important (in my sample code, the crash occurs when the circles have 144
|>vertices, it does not occur when they have only 72 vertices).

I think you may need to check you code closely, according to line "this.polylineTra = new Vector3[count + 1];", you actually created 145 vertices (0 - 144).
this is not a bug in Line.DrawTransform(), you get this behavior because your display card does not support D3DLINECAPS_ANTIALIAS. and in this scenario,
Line.DrawTransform() make a internal decision that uses D3DPT_TRIANGLELIST instead of D3DPT_LINESTRIP to draw the line.
As you have found, if we explicitly use D3DPT_LINESTRIP to consume the vertices buffer (eg. call Device.DrawUserPrimitives(PrimitiveType.LineStrip)), it will work fine.

Hope this clarify the problem. if there is anything unclear, please don't hesitate to let me know.

Best regards,
Rhett Gong [MSFT]
Microsoft Online Partner Support
Get Secure! -

This posting is provided "AS IS" with no warranties and confers no rights.