Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

arkasizer

Managed Direct3D & ProcessVertices

This topic is 5224 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everyone, I''ve been lurking around this forum for a while and have found it very informative. I am now in need of help on a topic that is rather new and I can''t seem to find info on it anywhere! I''m prototyping with Managed (C#) DirectX 9.0, and for batching purposes I want to use Device.ProcessVertices(). Whenever I call this function, however, I get a NullReferenceException from Direct3D.dll. Here is the code:
device.VertexFormat = CustomVertex.PositionTextured.Format;
				device.SetStreamSource(0, vertices, 0);
				device.SetTransform(
					TransformType.World,
					Matrix.Translation(10, 20, 0));

				/*** copied from MSDN documentation on VertexDeclaration: ***/
				// Create the vertex element array.

				VertexElement[] elements = new VertexElement[]
				{
					new VertexElement(0, 0, DeclarationType.Float3,
					DeclarationMethod.Default,
					DeclarationUsage.Position, 0),
					VertexElement.VertexDeclarationEnd 
				};

				// Use the vertex element array to create a vertex declaration.

				VertexDeclaration decl = new VertexDeclaration((device, elements);
				/*** End copy ***/

				device.ProcessVertices(
					0, 0, 4,
					Scene.transformedVB, 
					decl);					// null reference exception here

				device.VertexFormat = CustomVertex.TransformedTextured.Format;
				device.SetStreamSource(0, transformedVB, 0);
				device.DrawPrimitives(
					PrimitiveType.TriangleStrip,
					0,
					2);
I hope someone else has found a way to call ProcessVertices() from managed code. Any help appreciated. Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
Hi there,

I;ve noticed that that MSDN documention for managed DirectX is poor at best, and I suggest that the problem with you code might be the VertexElement[] because it only has one entry.

You can change your VertexElement if you have a mesh in your code to this

VertexElement[] elements = Mesh.Declaration;

the Declaration returns a VertexElement[] describing all the vertices of the mesh.

Good luck with that !


Share this post


Link to post
Share on other sites
Thanks for your reply. I don''t use meshes in my code as I am only working with individual primitives, or two primitives joined together to make a billboard. All my vertices use this same format so I don''t know what I would add to my array.

Defining a VertexElement array and using that to create a VertexDeclaration seems like an obscure way to simply describe a vertex format, when in all other cases you can use CustomVertex.PositionTextured.Format, etc.

I have also tried passing null to ProcessVertices instead of a VertexDeclaration, but I get the same error.

Beyond better documentation, MS should really take the time to flesh out their exception messages for the DirectX dll''s.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!