Vertex declaration and app crash

Started by
3 comments, last by george7378 10 years, 11 months ago

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!

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!

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).

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...

VladR My 3rd person action RPG on GreenLight: http://steamcommunity.com/sharedfiles/filedetails/?id=92951596

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!

This topic is closed to new replies.

Advertisement