Jump to content
  • Advertisement


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


DrawIndexedPrimitive fails

This topic is 5399 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, Im having some trouble getting a simple thing to work. That is creating a indexbuffer and calling DrawIndexedPrimitive. The vertices are created like this 0-----------------1 | | | | | | | | 2-----------------3 And the index buffer 0,1,2,1,3,2 There are two problems 1. The TextureLoader.FromFile( ... ) failes randomly with a "An unhandled exception of type 'System.ExecutionEngineException' occurred in microsoft.directx.direct3dx.dll" Its loading a larger large image, is there a limit for the size (there should be ) The point here is to load and display a background image. 2. The DrawIndexedPrimitive failes 4 out of 5 times. And if it's successful all i get is the bottom right tringle all black, sometimes. Other times it's just not there. I know that there might be no point in rendering two triangle using an indexbuffer, but the point is to learn here. Some source code: Setting up
// Create the vertexbuffer

Direct3D.CustomVertex.PositionTextured[] verts = 
				new Direct3D.CustomVertex.PositionTextured[4];

verts[0] = new Direct3D.CustomVertex.PositionTextured(0, 0, 0.0F, 0, 0);
verts[1] = new Direct3D.CustomVertex.PositionTextured(100, 0, 0.0F, 1, 0);
verts[2] = new Direct3D.CustomVertex.PositionTextured(0, 100, 0.0F, 0, 1);
verts[3] = new Direct3D.CustomVertex.PositionTextured(100, 100, 0.0F, 1, 1);

vertices = new Direct3D.VertexBuffer(typeof(Direct3D.CustomVertex.PositionTextured),
				verts.Length, base.gameApp.GraphicsMan.D3DDevice,
				0, Direct3D.CustomVertex.PositionTextured.Format, Direct3D.Pool.Default);

Direct3D.GraphicsStream stm = vertices.Lock(0, 0, 0);

indices = new Direct3D.IndexBuffer(
	6, 0, Direct3D.Pool.Default, false);

short[] s; // = new short[6];

s = (short[]) indices.Lock(0,typeof(short),

int i = 0;
s[i++] = 0;
s[i++] = 1;
s[i++] = 2;

s[i++] = 1;
s[i++] = 3;
s[i++] = 2;
// Load the texture

texture = Direct3D.TextureLoader.FromFile(base.gameApp.GraphicsMan.D3DDevice,

And rendering
Direct3D.Device dev = base.gameApp.GraphicsMan.D3DDevice;

// Draw some cool background

dev.VertexFormat = Direct3D.CustomVertex.PositionTextured.Format ; 
dev.SetStreamSource(0, vertices, 0); 
dev.Indices = indices;
dev.SetTexture(0, texture);
dev.DrawIndexedPrimitives(Direct3D.PrimitiveType.TriangleList, 0, 0, 4, 0, 2);

dev.SetTexture(0, null);

Thanks! /Johan [edited by - JohanK on November 9, 2003 4:35:18 AM]

Share this post

Link to post
Share on other sites
Some additional information:

At the times when it goes ok it draws the lower right triangle with the correct texture in it aswell. But when resizing it crashes. I've added an ondevicereset eventhandler to recreate the index and vertex buffer, and to reload the texture.

The error that gets thrown on

dev.DrawIndexedPrimitives(Direct3D.PrimitiveType.TriangleList, 0, 0, 4, 0, 2);

is this:

"An unhandled exception of type 'System.NullReferenceException' occurred in microsoft.directx.direct3d.dll"

By the way, its manager DX.

[edited by - JohanK on November 9, 2003 5:00:03 AM]

Share this post

Link to post
Share on other sites
Or I could be using CustomVertex.TransformedTextured instead of CustomVertex.PositionTextured... Problem solved anyhow...

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!