Jump to content
  • Advertisement
Sign in to follow this  
george7378

Vertex declaration and app crash

This topic is 1870 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'm having a problem with a certain part of my program - I think it's something to do with a vertex declaration. Basically, I have the following code to calculate a tangent frame for normal mapping:

 

D3DVERTEXELEMENT9 elements[] =

    {

        { 0, sizeof( float ) * 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },

        { 0, sizeof( float ) * 3, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 },

        { 0, sizeof( float ) * 6, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },

        { 0, sizeof( float ) * 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0 },

        { 0, sizeof( float ) * 15, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BINORMAL, 0 },

        D3DDECL_END()

    };



    LPD3DXMESH tempMesh = NULL;

    texturedMesh->CloneMesh(D3DXMESH_MANAGED, elements, renderdev, &tempMesh);
 
//Continue to calculate the tangent frame for the mesh...

 

The problem is that when I close the program, it triggers a breakpoint, which corresponds to a crash when I run the program outside of Visual Studio. The crash happens after I clean everything and release everything. I tried putting a breakpoint on every line in my cleanup routine, and even the last line of code in the program (return Msg.wParam;) and it still happens after this. The thing is, when I don't call my function to create a tangent frame, and hence don't use the above vertex declaration, the crash doesn't happen, so I guess it's something to do with that. What's the proper procedure for cleaning up after myself in this situation? There's no output in the debug window either, apart from some 'memory still allocated' errors.

 

Thanks!

Share this post


Link to post
Share on other sites
Advertisement

The most obvious thing that jumps out is that your offsets are incorrect, you have sizeof( float ) * 0, 3, 6, 12, 15. Where they should be 0, 3, 6, 9, 12. I'm guessing you copy/pasted from somewhere and removed something between the texcoord and tangent entries.

 

n!

Share this post


Link to post
Share on other sites

Ah, thanks for pointing that out, of course it makes sense, since each vector is 3 floats, that each one has the size of 3 floats! I must have changed it and forgotten!

 

Also, I seem to have fixed the problem by releasing tempMesh after calculating the tangent frame, which I didn't do before (I tried releasing it before calculating the tangent frame, but it didn't like that).

Share this post


Link to post
Share on other sites

This is one of those nice things that XNA runtime checks for you and you don't have to spend hours trying to find where you made the typo. It even gives you a beautiful exception with exact spot in either your declaration (or an actual VB) is messed up.

 

You were actually lucky to get a crash. But, that's exactly what the C++/DirectX combo brings to the table...

Share this post


Link to post
Share on other sites

Hm, well I'd trust that the debugger would either cause an exception of give me some feedback if there's something wrong, even if I do have to then manually find it. I think a lot of games today are done in C++ with DirectX so it must be popular for a reason!

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.

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

Sign me up!