He's back and stuck again!
CGame is a child class of base class CBase. CGame creates a private member of type CLaserTurret which is also a child of CBase. When I render the private member m_pLaserTurret, I get an Access Violation.
Function that crashes:
HRESULT CGame::Render ( )
{
if ( !g_pd3dDevice )
{
SetError ( "Unable to render because there's no device." );
return E_FAIL;
}
if ( FAILED ( m_ValidateDevice ( ) ) )
return E_FAIL;
g_pd3dDevice->Clear ( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,
D3DCOLOR_XRGB(0,0,64), 1.0f, 0 );
// Begin the scene
g_pd3dDevice->BeginScene ( );
m_SetupWorldMatrices ( );
////////////////////////////////////
m_pLaserTurret->m_Render ( ); // <-- This line crashes program
////////////////////////////////////
g_pd3dDevice->EndScene ( );
// Present the backbuffer contents to the display
g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
return S_OK;
}
Crashes on the if statement:
//--------------------------------------------------------------------
// CLaserTurret::m_Render ( )
//--------------------------------------------------------------------
void CLaserTurret::m_Render ( )
{
if( m_pMesh != NULL )
{
for( DWORD i = 0; i < m_dwNumMaterials; i++)
{
g_pd3dDevice->SetMaterial( &m_pMeshMaterials[i]);
g_pd3dDevice->SetTexture(0, m_pMeshTextures[i]);
m_pMesh->DrawSubset(i);
}
}
return;
}
I've tried moving everything in the CLaserTurret class to Public, but it doesn't help. I've also tried making CGame a friend of CLaserTurret.
Here's the definition of both classes:
CGame
#include "CBase.h"
class CLaserTurret;
#ifndef CGAME_HEADER
#define CGAME_HEADER
//------------------------------------------------
// Class CGame
//------------------------------------------------
class CGame : public CBase
{
public:
CGame ( );
virtual ~CGame ( );
void m_GameLoop ( );
HRESULT Render ( );
void m_SetupWorldMatrices ( );
HRESULT m_ValidateDevice ( );
private:
CLaserTurret* m_pLaserTurret;
};
#endif
CLaserTurret
#include "CBase.h"
#ifndef CLASERTURRET_HEADER
#define CLASERTURRET_HEADER
//------------------------------------------------
// Class m_CLaserTurret
//------------------------------------------------
class CLaserTurret : public CBase
{
public:
friend class CGame;
CLaserTurret ( );
virtual ~CLaserTurret ( );
void m_Render ( );
private:
DWORD m_dwNumMaterials;
LPD3DXMESH m_pMesh;
D3DMATERIAL8* m_pMeshMaterials;
LPDIRECT3DTEXTURE8* m_pMeshTextures;
};
#endif
Any information on what's wrong would be greatly appreciated!
[edited by - JimboC on August 4, 2002 6:23:27 PM]