Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Error when program terminates


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 thestien   Members   -  Reputation: 102

Like
0Likes
Like

Posted 26 March 2012 - 03:47 PM

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 Posted Image

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 Posted Image

Sponsor:

#2 Endurion   Crossbones+   -  Reputation: 3694

Like
0Likes
Like

Posted 26 March 2012 - 11:18 PM

Hell, use std::list or something.

You are free-ing your objects. Are they malloc-ed or new-ed?
Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

#3 thestien   Members   -  Reputation: 102

Like
0Likes
Like

Posted 27 March 2012 - 12:55 AM

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 :)

#4 NightCreature83   Crossbones+   -  Reputation: 3036

Like
0Likes
Like

Posted 27 March 2012 - 02:57 AM

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.
Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, Mad Max

#5 thestien   Members   -  Reputation: 102

Like
0Likes
Like

Posted 27 March 2012 - 12:49 PM

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[i].m_Material = pMaterials[i].MatD3D;
        m_pMaterials[i].m_Material.Ambient = m_pMaterials[i].m_Material.Diffuse;

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

            continue;
        }

        r = D3DXCreateTextureFromFile( g_pDevice, pMaterials[i].pTextureFilename, &m_pTextures[i]);
        if( FAILED( r))
        {
            SetError("unable to load texture for mesh with filename");
            SetError( pMaterials[i].pTextureFilename);
            m_pTextures[i] = 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?




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS