Skip to main content
gamedev.net
🔒 Locked

problem with "new" debugging

Started by maya18222 0 replies 2.3k views
Original Post
maya18222
maya18222
ive been trying to use the debug functionality below with directx, but am having trouble trying to get it working with "d3dx9math.h", one of the matrix types which im not even using, wont work with it.

#ifdef _DEBUG
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#include <stdlib.h>
#define DEBUG_NEW new(_CLIENT_BLOCK, __FILE__, __LINE__)
#define new DEBUG_NEW
#endif

#if defined(DEBUG) | defined(_DEBUG)
		_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif


I get the following errors

Error	2	error C2059: syntax error : 'constant'	c:\program files\microsoft directx sdk (august 2008)\include\d3dx9math.h	392	ParticleEngine
Error	3	error C2091: function returns function	c:\program files\microsoft directx sdk (august 2008)\include\d3dx9math.h	392	ParticleEngine
Error	4	error C2802: static member 'operator new' has no formal parameters	c:\program files\microsoft directx sdk (august 2008)\include\d3dx9math.h	392	ParticleEngine
Error	5	error C2059: syntax error : 'constant'	c:\program files\microsoft directx sdk (august 2008)\include\d3dx9math.h	393	ParticleEngine
Error	6	error C2090: function returns array	c:\program files\microsoft directx sdk (august 2008)\include\d3dx9math.h	393	ParticleEngine
Error	7	error C2761: 'void *(__cdecl *_D3DXMATRIXA16::operator new(void))(size_t)' : member function redeclaration not allowed	c:\program files\microsoft directx sdk (august 2008)\include\d3dx9math.inl	990	ParticleEngine
Error	8	fatal error C1903: unable to recover from previous error(s); stopping compilation	c:\program files\microsoft directx sdk (august 2008)\include\d3dx9math.inl	990	ParticleEngine


this is the matrix type thats causing the problem

//---------------------------------------------------------------------------
// Aligned Matrices
//
// This class helps keep matrices 16-byte aligned as preferred by P4 cpus.
// It aligns matrices on the stack and on the heap or in global scope.
// It does this using __declspec(align(16)) which works on VC7 and on VC 6
// with the processor pack. Unfortunately there is no way to detect the 
// latter so this is turned on only on VC7. On other compilers this is the
// the same as D3DXMATRIX.
//
// Using this class on a compiler that does not actually do the alignment
// can be dangerous since it will not expose bugs that ignore alignment.
// E.g if an object of this class in inside a struct or class, and some code
// memcopys data in it assuming tight packing. This could break on a compiler
// that eventually start aligning the matrix.
//---------------------------------------------------------------------------
#ifdef __cplusplus
typedef struct _D3DXMATRIXA16 : public D3DXMATRIX
{
    _D3DXMATRIXA16() {}
    _D3DXMATRIXA16( CONST FLOAT * );
    _D3DXMATRIXA16( CONST D3DMATRIX& );
    _D3DXMATRIXA16( CONST D3DXFLOAT16 * );
    _D3DXMATRIXA16( FLOAT _11, FLOAT _12, FLOAT _13, FLOAT _14,
                    FLOAT _21, FLOAT _22, FLOAT _23, FLOAT _24,
                    FLOAT _31, FLOAT _32, FLOAT _33, FLOAT _34,
                    FLOAT _41, FLOAT _42, FLOAT _43, FLOAT _44 );

    // new operators
    void* operator new   ( size_t );
    void* operator new[] ( size_t );

    // delete operators
    void operator delete   ( void* );   // These are NOT virtual; Do not 
    void operator delete[] ( void* );   // cast to D3DXMATRIX and delete.
    
    // assignment operators
    _D3DXMATRIXA16& operator = ( CONST D3DXMATRIX& );

} _D3DXMATRIXA16;

#else //!__cplusplus
typedef D3DXMATRIX  _D3DXMATRIXA16;
#endif //!__cplusplus



#if _MSC_VER >= 1300  // VC7
#define D3DX_ALIGN16 __declspec(align(16))
#else
#define D3DX_ALIGN16  // Earlier compiler may not understand this, do nothing.
#endif

typedef D3DX_ALIGN16 _D3DXMATRIXA16 D3DXMATRIXA16, *LPD3DXMATRIXA16;

_moagstar_
_moagstar_
The problem here is that you are #defineing new, so what the preprocessor is doing is turning :

    // new operators    void* operator new   ( size_t );    void* operator new[] ( size_t );


into :

    // new operators    void* operator new(_CLIENT_BLOCK, "<filename>", <line number>) ( size_t );    void* operator new(_CLIENT_BLOCK, "<filename>", <line number>)[] ( size_t );


If you want to do this then you should #define new only in .cpp files after you have included all other headers, if you want to be really safe then just allocate memory using DEBUG_NEW instead of new, it makes your code a bit uglier though.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.