Jump to content
  • Advertisement
Sign in to follow this  
thestien

Error when program terminates

This topic is 2248 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys i have just posted another thread a min ago but i didnt want to put to many subjects in one thread so i started this one smile.png

i am getting an error when my program shuts down HEAP[classfull.exe]: Invalid address specified to RtlValidateHeap( 006D0000, 00593710 )
Windows has triggered a breakpoint in classfull.exe.

This may be due to a corruption of the heap, which indicates a bug in classfull.exe or any of the DLLs it has loaded.

This may also be due to the user pressing F12 while classfull.exe has focus.

The output window may have more diagnostic information.



i think this is happening when i add objects or frames to a parent frame( or to a child or any frame lol)
i had this error when loading only one frame with one mesh and when i commented out the addobject() i didnt get the error anymore.


class CZenFrame;
typedef int (*FRAME_MOVEMENT_CALLBACK)( CZenFrame* pFrame, void* Parameter);


class CZenFrame
{
public:
CZenFrame();
~CZenFrame();

void* m_pParameter;

// Variables

protected:
D3DXMATRIX m_Local;
D3DXVECTOR3 m_vPosition;
D3DXVECTOR3 m_vVelocity;

float m_Yaw, m_Pitch, m_Roll;

CZenObject* m_pObjectList;
CZenFrame* m_pNext;
CZenFrame* m_pChildFrameList;
CZenFrame* m_pParentFrame;
FRAME_MOVEMENT_CALLBACK m_pfnCallback;
BOOL m_bCallback;


public:
HRESULT SetCallback( FRAME_MOVEMENT_CALLBACK pfnCallback);

void SetVelocity( float x, float y, float z);
void GetVelocity( float& x, float& y, float& z);

void SetPosition( float x, float y, float z);
void GetPosition( float& x, float& y, float& z);

void GetLocal( D3DXMATRIX& pMatrix);

void SetYaw( float Yaw){ m_Yaw = Yaw;}
void GetYaw( float& Yaw){ Yaw= m_Yaw;}

void SetPitch( float Pitch){ m_Pitch = Pitch;}
void GetPitch( float& Pitch){ Pitch = m_Pitch;}

void SetRoll( float Roll){ m_Roll = Roll;}
void GetRoll( float& Roll){ Roll = m_Roll;}

void Update();

HRESULT AddObject( CZenObject* pNewObject);
HRESULT Render();

void SetNext( CZenFrame* pNext){ m_pNext = pNext;}
CZenFrame* GetNext(){ return m_pNext;}
HRESULT AddFrame( CZenFrame* pNewFrame);

protected:
void SetParent( CZenFrame* pParent){ m_pParentFrame = pParent;}
CZenFrame* GetParent(){ return m_pParentFrame;}

};


HRESULT CZenFrame::AddFrame( CZenFrame* pNewFrame)
{
if( !pNewFrame)
{
SetError( "Failed to add child frame");
return E_FAIL;
}

pNewFrame->SetParent( this);

if( !m_pChildFrameList)
{
m_pChildFrameList = pNewFrame;
}
else
{
CZenFrame* pTempFrame = m_pChildFrameList;

while( pTempFrame->GetNext())
pTempFrame = pTempFrame->GetNext();

pTempFrame->SetNext( pNewFrame);
}

return S_OK;
}


HRESULT CZenFrame::AddObject( CZenObject* pNewObject)
{

if( !pNewObject)
return E_FAIL;

pNewObject->SetParentFrame( this);

if( !m_pObjectList)
{
m_pObjectList = pNewObject;
}
else
{
CZenObject* pObject = m_pObjectList;

while( pObject->GetNext())
pObject = (CZenObject*)pObject->GetNext();

pObject->SetNext( pNewObject);
}

return S_OK;
}


CZenFrame::~CZenFrame()
{

CZenObject* pObject = m_pObjectList;
CZenObject* pTemp = 0;

while( pObject)
{

pTemp = (CZenObject*)pObject->GetNext();
free( pObject);
pObject = pTemp;

}

}



can you see any obvious causes for this error?

many thanks in advance smile.png

Share this post


Link to post
Share on other sites
Advertisement
this code is from a book i will look into std::list today and try to convert this code to use it. there is only one place in my program where i make NEW thats in the object class when i load materials and textures from the Xfile but they are delete[] in the mesh destructor.

will delete[] stuff; delete all of the things i have new-ed into that pointer?

thanks again for teh reply :)

Share this post


Link to post
Share on other sites
Delete[] should only be used on a pointer that was allocated with new[] otherwise you get undefined behaviour. If you create your own list and you have to walk that list and delete all the data that you have allocated with new or new[] with delete or delete[] but they have to match so if you used new use delete.

Also don't mix delete or delete[] with malloc allocations, or use free on new/new[] allocated memory. that will also lead to undefined behaviour.

Share this post


Link to post
Share on other sites
Hi This is how the x file is loaded and its the only place in my code with NEW
HRESULT CZenMesh::LoadXFile( char* pstrPathName)
{
HRESULT r = 0;

LPD3DXBUFFER pMaterialBuffer = 0;

r = D3DXLoadMeshFromX(pstrPathName, D3DXMESH_MANAGED, g_pDevice, 0, &pMaterialBuffer,
0, (DWORD*)&m_NumMats, &m_pMesh);
if( FAILED( r))
{
SetError(" failed to load x file with filename:");
SetError(" pstrPathname");
return E_FAIL;
}
m_pTextures = new LPDIRECT3DTEXTURE9[m_NumMats];
m_pMaterials = new CZenMaterial[m_NumMats];

D3DXMATERIAL* pMaterials = (D3DXMATERIAL*)pMaterialBuffer->GetBufferPointer();

for( int i = 0; i < m_NumMats; i++)
{
m_pMaterials.m_Material = pMaterials.MatD3D;
m_pMaterials.m_Material.Ambient = m_pMaterials.m_Material.Diffuse;

if( !pMaterials.pTextureFilename)
{
m_pTextures = g_pDefaultTexture;

continue;
}

r = D3DXCreateTextureFromFile( g_pDevice, pMaterials.pTextureFilename, &m_pTextures);
if( FAILED( r))
{
SetError("unable to load texture for mesh with filename");
SetError( pMaterials.pTextureFilename);
m_pTextures = g_pDefaultTexture;
}
}

pMaterialBuffer->Release();
return S_OK;
}


here is the destructor for the Frame and mesh class


CZenFrame::~CZenFrame()
{

CZenObject* pObject = m_pObjectList;
CZenObject* pTemp = 0;

while( pObject)
{

pTemp = (CZenObject*)pObject->GetNext();
free( pObject);
pObject = pTemp;

}

}

CZenMesh::~CZenMesh()
{

delete [] m_pMaterials;
delete [] m_pTextures;


}


i wrote the mesh destructor because there isnt one in the book. is that the right way to delete those news?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!