Array of ID3DXMesh (dynamic allocation)
Hi folks !
I want to create dynamically ID3DXMesh object when needed. My first idea was to do it like this...
ID3DXMesh* m_pPuzzleMesh;
m_pPuzzleMesh = new ID3DXMesh[ m_PuzzleLevel.nbPuzzlePiece ];
( 3D puzzle game, I have puzzle level and many puzzle pieces )
( m_PuzzleLevel.nbPuzzlePiece is the number of pieces in my level)
I got the following error...
error C2259: 'ID3DXMesh' : cannot instantiate abstract class
I don't know at the moment of the declaration of m_pPuzzleMesh how many puzzle
pieces I will have. The maximum is 1600. So at first time, I did it like the following... and it works.
ID3DXMesh* m_pPuzzleMesh[1600];
and after that when I know the number of puzzle pieces, I instantiate each
m_pPuzzleMesh with D3DXCreateMeshFVF(...) ...
It works fine but now I want to create only the number of ID3DXMesh instance I NEED. I want to use also std:vector<ID3DXMesh*> if possible.
I check around on the web 1 hour but I always have error.
Can someone help me !
Thanks.
Quote:Original post by Danny Gilbert
It works fine but now I want to create only the number of ID3DXMesh instance I NEED. I want to use also std:vector<ID3DXMesh*> if possible.
I check around on the web 1 hour but I always have error.
Yea, it should be very easy to use std::vector for this. What error are you having? If you need documentation, check this.
If you want to have a dynamic amount of meshes, then store pointers to the interface pointers...
Or use a std::vector of ID3DXMesh**'s.
Dave
ID3DXMesh** pMeshPointers = new ID3DXMesh*[1000];
Or use a std::vector of ID3DXMesh**'s.
Dave
Hi ! Thank you for the hint. I got other problem like...
DAMAGE: after normal block (#103)
It seems to be difficult to debug this kind of error but my code
seems ridiculously easy.
The following works...
-----------------------
ID3DXMesh* m_pMeshPointers[1600];
use of m_pMeshPointers .. OK
and delete for each i like this...
for( i = 0; i < m_PuzzleLevel.nbPuzzlePiece; i++)
{
SAFE_RELEASE( m_pMeshPointers );
}
where...
#define SAFE_RELEASE(p) { if(p) { (p)->Release(); (p)=NULL; } }
The following does not work... must be the same except that is is dynamic (I use new keyword and delete ).
ID3DXMesh** m_pMeshPointers; // Declaration
m_pMeshPointers = new ID3DXMesh*[ m_PuzzleLevel.nbPuzzlePiece ]; // Construction
use of m_pMeshPointers .. OK
SAFE_RELEASE( m_pMeshPointers ); // Deletion
where m_PuzzleLevel.nbPuzzlePiece is a value readed elsewhere at run time and value is smaller than 1600.
Thanks !
DAMAGE: after normal block (#103)
It seems to be difficult to debug this kind of error but my code
seems ridiculously easy.
The following works...
-----------------------
ID3DXMesh* m_pMeshPointers[1600];
use of m_pMeshPointers .. OK
and delete for each i like this...
for( i = 0; i < m_PuzzleLevel.nbPuzzlePiece; i++)
{
SAFE_RELEASE( m_pMeshPointers );
}
where...
#define SAFE_RELEASE(p) { if(p) { (p)->Release(); (p)=NULL; } }
The following does not work... must be the same except that is is dynamic (I use new keyword and delete ).
ID3DXMesh** m_pMeshPointers; // Declaration
m_pMeshPointers = new ID3DXMesh*[ m_PuzzleLevel.nbPuzzlePiece ]; // Construction
use of m_pMeshPointers .. OK
SAFE_RELEASE( m_pMeshPointers ); // Deletion
where m_PuzzleLevel.nbPuzzlePiece is a value readed elsewhere at run time and value is smaller than 1600.
Thanks !
Quote:Original post by Danny GilbertThat means you're writing past the end of your array somewhere. Look at everywhere you're writing to the array and make sure that you don't go over the end of the array and that you don't have any "off by one" errors anywhere.
DAMAGE: after normal block (#103)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement