Re: Exception raised when drawing many circles
- From: Andrew Vardeman <andrewv@xxxxxxxxxxx>
- Date: Fri, 16 Sep 2005 15:00:04 -0500
I have just observed this error for the first time myself today. I make an array of Vector3's that is the appropriate length (the number of vertices in the line string I want to draw). For lines trings with a small number of vertices, this works just fine. For line strings with a large number of vertices, this fails with the following error:
****
First-chance exception at 0x067bf026 in NriCertify.exe: 0xC0000005: Access violation writing location 0x05e12000.
System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.DirectX.Direct3D.Line.DrawTransform(Vector3[] vertexList, Matrix transform, Int32 color)
at Microsoft.DirectX.Direct3D.Line.DrawTransform(Vector3[] vertexList, Matrix transform, Color color)
at NRI.D3dSpatialDataRender.D3dUtil.DrawLines(Device d, Matrix viewMatrix, Matrix projectionMatrix, Vector3[] lineVerts, Int32 width, Color color) in c:\nrisvn\geolibs\trunk\d3dspatialdatarender\d3dutil.cs:line 114
Direct3D9: (ERROR) :Vertex buffer must be unlocked during DrawPrimitive call
****
I don't quite follow your response to Olivier, but I fail to see how this behavior could be anything but a bug in the Line class. As I understand it, Line.DrawTransform() promises to take a list of points that describe a series of connected lines and render the specified lines with a specified width. If the method fails to do this, that's a bug. It is not the responsibility of the consumer of an API to anticipate the internal decisions made by an algorithm and adjust input accordingly, which is what you suggest. If the Line class chooses to draw the lines as polygons, it has the responsibility of generating those polygons (and allocating sufficient space to store them) itself. This is why there is a utility class for line drawing in the first place.
I'd guess what's going on is that the Line class or something it wraps makes some assumption about a maximum buffer size and fails to reallocate properly when a request is made to draw lines that require a larger buffer. If you'd like, I can experiment to find the number of vertices at which Line.DrawTransform() first fails. I'm eager to get this solved, since it's limiting the size of polygons users are allowed to create in our 2D application.
Andrew
Rhett Gong [MSFT] wrote:
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)), 0.0f); } }
// 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! - www.microsoft.com/security
http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.asp&SD=msdn
This posting is provided "AS IS" with no warranties and confers no rights.
.
- References:
- Exception raised when drawing many circles
- From: Olivier Lauffenburger
- RE: Exception raised when drawing many circles
- From: Rhett Gong [MSFT]
- RE: Exception raised when drawing many circles
- From: Olivier Lauffenburger
- RE: Exception raised when drawing many circles
- From: Rhett Gong [MSFT]
- RE: Exception raised when drawing many circles
- From: Olivier Lauffenburger
- RE: Exception raised when drawing many circles
- From: Rhett Gong [MSFT]
- RE: Exception raised when drawing many circles
- From: Olivier Lauffenburger
- RE: Exception raised when drawing many circles
- From: Rhett Gong [MSFT]
- RE: Exception raised when drawing many circles
- From: Rhett Gong [MSFT]
- RE: Exception raised when drawing many circles
- From: Rhett Gong [MSFT]
- Exception raised when drawing many circles
- Prev by Date: Re: Line.DrawTransform Collection
- Next by Date: Re: Rendering Text into a texture
- Previous by thread: RE: Exception raised when drawing many circles
- Next by thread: RE: Exception raised when drawing many circles
- Index(es):
Relevant Pages
|