Jump to content

  • Log In with Google      Sign In   
  • Create Account

Vertex declaration and app crash


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 george7378   Members   -  Reputation: 1226

Like
0Likes
Like

Posted 09 May 2013 - 04:20 AM

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!



Sponsor:

#2 nfactorial   Members   -  Reputation: 729

Like
2Likes
Like

Posted 09 May 2013 - 06:22 AM

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!



#3 george7378   Members   -  Reputation: 1226

Like
0Likes
Like

Posted 09 May 2013 - 07:02 AM

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



#4 VladR   Members   -  Reputation: 722

Like
1Likes
Like

Posted 09 May 2013 - 08:54 AM

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

 


#5 george7378   Members   -  Reputation: 1226

Like
0Likes
Like

Posted 09 May 2013 - 10:43 AM

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!






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS