When I debug my program, I get this error:
Unhandled exception at 0x004d2776 in engine.exe: 0xC0000005: Access violation reading location 0xccccccd0.
This is the stack trace:
> engine.exe!CEntityController::SpawnEntities() Line 18 + 0x24 bytes C++
engine.exe!CEntityController::Start() Line 50 C++
engine.exe!DarkGDK() Line 21 C++
engine.exe!_WinMain@16() + 0x13 bytes C++
engine.exe!__tmainCRTStartup() Line 263 + 0x1b bytes C
This is the code for SpawnEntities( ):
void CEntityController::SpawnEntities( )
{
for( int i = 0; i < m_vEntities.size( ); ++i )
m_vEntities[i]->Spawn( );
}
At the moment there isn't actually any code inside spawn, so it must be either m_vEntities isn't initialized, or m_vEntities isn't initialized. I think m_vEntities gets initialized automatically when CEntityController gets constructed. Here is where entities get added to m_vEntities:
CBaseEntity::CBaseEntity( )
:m_sModelName( "" ), m_nModelID( 0 ), m_vOrigin( VEC( 0.0f, 0.0f, 0.0f ) ),
m_bOriginSet( false )
{
gpGlobals.controller.AddEntity( this );
}
Here is the code for AddEntity( ):
void CEntityController::AddEntity( CBase *pEntity )
{
m_vEntities.push_back( pEntity );
}
I've looked around in my code, and I can't find any variables that have been assigned that address(0xccccccd0).
Here is the code for my CBaseEntity class, since attaching files isn't working:
header:
#ifndef BASEENTITY_H
#define BASEENTITY_H
#include "defines.h"
#include "cbase_class.h"
#include "string.h"
#include "vector.h"
#include "entitycontroller.h"
class CBaseEntity : public CBase{
STR m_sModelName;
STR m_sName;
unsigned int m_nModelID;
VEC m_vOrigin;
bool m_bOriginSet;
public:
DECLARE_CLASS( CBaseEntity, CBase );
CBaseEntity( );
~CBaseEntity( );
STR GetModelName( );
unsigned int GetModelID( );
void SetModel( char *pFileName );
void SetModelDebugMode( );
void SetOrigin( VEC vOrigin );
void SetName( char *pName );
virtual void Think( );
virtual void Spawn( );
virtual void Activate( );
virtual void Delete( );
};
#endif //BASEENTITY_H
source file:
//---------------------------------------------//
// Copyright Tom Tetlaw(C) 2010
//-----------------------------------------//
#include "DarkGDK.h"
#include "baseentity.h"
#include "globals.h"
CBaseEntity::CBaseEntity( )
:m_sModelName( "" ), m_nModelID( 0 ), m_vOrigin( VEC( 0.0f, 0.0f, 0.0f ) ),
m_bOriginSet( false )
{
gpGlobals.controller.AddEntity( this );
}
CBaseEntity::~CBaseEntity( )
{
gpGlobals.model_id_manager.RemoveID( );
}
STR CBaseEntity::GetModelName( )
{
return m_sModelName;
}
unsigned int CBaseEntity::GetModelID( )
{
return m_nModelID;
}
void CBaseEntity::SetModel( char *pFileName )
{
if( dbObjectExist( m_nModelID ) )
{
dbDeleteObject( m_nModelID );
}
m_nModelID = gpGlobals.model_id_manager.GetNextID( );
dbLoadObject( pFileName, m_nModelID );
}
void CBaseEntity::SetModelDebugMode( )
{
if( m_sModelName.PtrValue( ) == "models/debug_mode.x" )
{
dbDeleteObject( m_nModelID );
return;
}
SetModel( "models/debug_mode.x" );
}
void CBaseEntity::SetOrigin( VEC vOrigin )
{
if( m_bOriginSet )
return;
m_vOrigin = vOrigin;
dbPositionObject( m_nModelID, m_vOrigin.x, m_vOrigin.y, m_vOrigin.z );
m_bOriginSet = true;
}
void CBaseEntity::Think( )
{
}
void CBaseEntity::Spawn( )
{
SetModelDebugMode( );
}
void CBaseEntity::Activate( )
{
}
void CBaseEntity::Delete( )
{
}
void CBaseEntity::SetName( char *pName )
{
m_sName = pName;
}
I just need to find out why it's giving me that error, your time and effort to help me will be appreciated. :)