-
January 3rd, 2015, 02:29 AM
#1
How to initialize an array of DirectX9 Objects?
Hello,
I've got an error saying that there is an access violation at 0x0000040
error no 0xC0000005
I've searched the net, saying the error may be due to an uninitialzed variable.
I debugged the code, and found out that an object created from directx D3DXMATRIXA16 is uninitialized.
With values ??,??,?? in each element
pMeshContainer->pBoneMatrices = new D3DXMATRIXA16[g_NumBoneMatricesMax];
here, pMeshContainer is a variable passed into a function called GenerateSkinnedMesh by pointer
GenerateSkinnedMesh(..., D3DXMESHCONTAINER_DERIVED *pMeshContainer)
Then in turn, GenerateSkinnedMesh is called within a callback from a DirectX9 API called
ID3DXAllocateHierarchy
Code:
class CAllocateHierarchy : public ID3DXAllocateHierarchy
{
public:
STDMETHOD( CreateFrame )( THIS_ LPCSTR Name, LPD3DXFRAME *ppNewFrame );
STDMETHOD( CreateMeshContainer )( THIS_
LPCSTR Name,
CONST D3DXMESHDATA *pMeshData,
CONST D3DXMATERIAL *pMaterials,
CONST D3DXEFFECTINSTANCE *pEffectInstances,
DWORD NumMaterials,
CONST DWORD *pAdjacency,
LPD3DXSKININFO pSkinInfo,
LPD3DXMESHCONTAINER *ppNewMeshContainer );
STDMETHOD( DestroyFrame )( THIS_ LPD3DXFRAME pFrameToFree );
STDMETHOD( DestroyMeshContainer )( THIS_ LPD3DXMESHCONTAINER pMeshContainerBase );
CAllocateHierarchy()
{
}
};
when the method CreateMeshContainer finished execution,
the meshContainer is passed back to its parent like this
*ppMeshContainer = pMeshContainer;
The whole meshContainer stuff is stored persistently inside the frame root wrapped within a class called
CMesh
So in that process, I haven't initialized pBoneMatrices in anyways. But what and where is the best way to
initialize an array of DirectX9 objects.
There is a function called
D3DXMatrixIdentity(&...);
But how can I initialize each one of them with this call?
Notice that pMeshContainer->pBoneMatrices does contain a valid address, despite the fact that
the elements inside it are never initialized...
Thanks
Jack
-
January 4th, 2015, 10:26 PM
#2
Re: How to initialize an array of DirectX9 Objects?
1) Are you debugging a release build or a debug build?
2) This:
Code:
pMeshContainer->pBoneMatrices = new D3DXMATRIXA16[g_NumBoneMatricesMax];
does not default initialize the members of the struct. This does:
Code:
pMeshContainer->pBoneMatrices = new D3DXMATRIXA16[g_NumBoneMatricesMax]();
Regards,
Paul McKenzie
-
January 6th, 2015, 02:47 PM
#3
Re: How to initialize an array of DirectX9 Objects?
Is this
Originally Posted by Paul McKenzie
Code:
pMeshContainer->pBoneMatrices = new D3DXMATRIXA16[g_NumBoneMatricesMax]();
not called "value initialisation" as opposed to "default initialisation" which, for POD types, does nothing at all?
-
January 6th, 2015, 02:50 PM
#4
Re: How to initialize an array of DirectX9 Objects?
Originally Posted by Richard.J
not called "value initialisation" as opposed to "default initialisation" which, for POD types, does nothing at all?
Value initialisation means zero initialisation in such cases.
-
January 6th, 2015, 04:23 PM
#5
Re: How to initialize an array of DirectX9 Objects?
I am not sure if I understand correctly.
Say you have
Code:
int *p = new int[3];
This leaves you with a default initialised array which may contain any value, depending on the compiler, doesn't it?
On the other hand,
Code:
int *p = new(int[3])();
gives you an array of three ints, all initialised to zero?
At least this is what I think I understood using VC2010.
Are there differences regarding the different C++ standards?
-
January 6th, 2015, 11:04 PM
#6
Re: How to initialize an array of DirectX9 Objects?
Yeah. I think that the standard has not changed in this respect: C++11 introduced standard layout types, but these initialisation rules were specified with respect to class types, array types and other types, not specfically POD types.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|