Jump to content
  • Advertisement
Sign in to follow this  

Vertex Declaration Error

This topic is 2112 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



I've got a starnge error happening in DX9 when I try call DrawIndexedPrimitive().


My vertex declaration is a simple position only declaration, my vertex buffer is a 33 x 33 grid and my index buffer is set up to draw 32 x 32 x 2 triangles - essentially this is a terrain patch.  I've been using ID3DXMesh which works fine using the exact same vertex and index buffer setup.


Direct3D9: Decl Validator: X1065: (Element Error) (Decl Element [0]) Offset must be multiple of DWORD size (4 bytes). Encountered offset: 550

Direct3D9: Decl Validator: X281: (Element Error) (Decl Element [0]) Usage field contains value that is not a member of D3DDECLUSAGE. Value: 0x26. Aborting decl validation.


the 'Encountered offset' value seems to change each time I run it.


Aside other effect settings, I just call:


graphicsDevice->SetStreamSource(0,  vertexBuffer, sizeof(LVec3));




then (for testing I'm just drawing one triangle but supplying the whole vertex buffer):

graphicsDevice->DrawIndexedPrimitive(4, 0, 0, 33 * 33, 0, 1);


Here's my vertex declaration:


LVE* decl_PosOnly = new LVE[2];

decl_PosOnly[0] = LVE(0, 0, LVE_TypeFloat3, LVE_MethodDefault, LVE_UsagePosition, 0);

decl_PosOnly[1] = LVE_END();

graphicsDevice->RegisterVertexDeclaration(decl_PosOnly, PositionOnly);

This all essentially resolves down to the exact same structure as a D3DVERTEXELEMENT9

I'm wondering whether I'm writing over some memory somewhere but very little has changed since meshes worked


Anyone seen this error before?

Share this post

Link to post
Share on other sites

That type of error sounds like your declaration array is getting borked somehow.  At the time that you are calling the device method for creating the declaration, can you double check the return code to see if it is catching the error there?  Also, it has been a long time since I worked with D3D9, but what is the LVE type that you are using to create the declaration element array?  If that type doesn't match exactly the declaration type then you could be getting an offset error that way...

Share this post

Link to post
Share on other sites

Thanks for the post..


I get S_OK for everything I'm setting, indices, vertices and vertexdeclaration.  My LVE is essentially the exact same format as DX's:



typedef struct 
   LVE(U16 s, U16 o, U8 t, U8 m, U8 u, U8 ui)
      stream = s;
      offset = o;
      type = t;
      method = m;
      usage = u;
      usageIndex = ui;
   U16 stream; // Stream index
   U16 offset; // Offset in the stream in bytes
   U8 type; // Data type
   U8 method; // Processing method
   U8 usage; // Semantics
   U8 usageIndex; // Semantic index
} LVE;
// This is used to initialize the last vertex element in a vertex declaration array
#define LVE_END() LVE(0xFF, 0, LVE_TypeUnsued, 0, 0, 0)

LVE_TypeUnused resolves down to the same thing in DX9


I can render everything as a mesh and in fact my animated model renders fine (using a mesh again) and the vertex declaration for that is obviously very different.

Share this post

Link to post
Share on other sites

I figured this out.  My vertex declaration objects contain a void* to the native declaration (on the DX side) - my graphics library is abstratcted away from my game layer.  When I set the vertex declaration, it wasn't obvious but the IDirect3DVertexDeclaration9 had a NULL IUnknown pointer - when I create my game-side version of the declaration, I was setting the native pointer incorrectly.


Thanks Jason

Share this post

Link to post
Share on other sites

You are welcome :)  Thanks for sharing the update - hopefully it will help someone else down the road.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!