Sign in to follow this  
raelag

Problem with struct inheritance in SkinedMesh

Recommended Posts

I loaded the SkinedMesh from DirectX SDK Sample and it could run well. Then I added the original member declarations of D3DXFRAME and D3DXMESHCONTAINER to the derived structs like this:
struct D3DXFRAME_DERIVED: public D3DXFRAME
{
	//------------Original D3DXFRAME members-----------------//
	LPSTR                   Name;
    D3DXMATRIX              TransformationMatrix;

    LPD3DXMESHCONTAINER     pMeshContainer;

    D3DXFRAME       *pFrameSibling;
    D3DXFRAME       *pFrameFirstChild;

	//------------New members-------------------------------//
    D3DXMATRIXA16        CombinedTransformationMatrix; 
};
struct D3DXMESHCONTAINER_DERIVED: public D3DXMESHCONTAINER
{
	//-----------Original D3DXMESHCONTAINER members------//
    LPSTR                   Name;

    D3DXMESHDATA            MeshData;

    LPD3DXMATERIAL          pMaterials; 
    LPD3DXEFFECTINSTANCE    pEffects; 
    DWORD                   NumMaterials; 
    DWORD                  *pAdjacency; 

    LPD3DXSKININFO          pSkinInfo;

    D3DXMESHCONTAINER *pNextMeshContainer;

	//-----------New members-----------------------------//
    LPDIRECT3DTEXTURE9*  ppTextures;                                       
    // SkinMesh info             
    LPD3DXMESH           pOrigMesh; // Original Mesh loaded
    LPD3DXATTRIBUTERANGE pAttributeTable; 
    DWORD                NumAttributeGroups; 
    DWORD                NumInfl; 
    LPD3DXBUFFER         pBoneCombinationBuf; 
    D3DXMATRIX**         ppBoneMatrixPtrs; 
    D3DXMATRIX*          pBoneOffsetMatrices; 
    DWORD                NumPaletteEntries;
    bool                 UseSoftwareVP;
    DWORD                iAttributeSW;     
};
The program breaks at D3DXLoadMeshHierarchyFromX(...) Why's that? Can't I override struct or class variables?

Share this post


Link to post
Share on other sites
When you say the program 'breaks', are you referring to a compiler error, or a runtime error? More information would be useful (such as the exact error message).

Also, why do want to override member variables of the base class? You can certainly do this, but it's somewhat confusing and can easily lead to trouble (especially when pointers are involved, as is the case here).

Share this post


Link to post
Share on other sites
A runtime error:
Unhandled exception at 0x006fefdc in SkinnedMesh.exe: 0xC0000005: Access violation reading location 0xcdcdcdcd.

I think I know the reason.

D3DXFRAME_DERIVED a;
a.name is not identical to ((D3DXFRAME)a).name

Share this post


Link to post
Share on other sites
Quote:
Original post by raelag
I think I know the reason.

D3DXFRAME_DERIVED a;
a.name is not identical to ((D3DXFRAME)a).name
Do you mean Name? (I don't see a variable named name...)

If so, then yes, that's exactly the sort of problem I was referring to earlier.

Again, why do want to override member variables of the base class?

Share this post


Link to post
Share on other sites
Quote:

Again, why do want to override member variables of the base class?

Only for convenience. I want to refer to the definition of the members more easily. I can comment them as well.
Thanks.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this