M
manuthomas23
Here is the code:
#ifndef M3DCAMERA__H__
#define M3DCAMERA__H__
class M3DEngine;
/**
Micro3D Camera class.
*/
class M3DCam
{
public:
virtual void Init(EngineData *ed);
.
.
.
protected:
IMicro3D *m_pmicro3d; ///<Micro3D interface pointer.
Vec3i m_pos; ///<Position of the camera.
Vec3i m_target; ///<Target of the camera.
Vec3i m_up; ///<Camera up direction vector.
Atrans3i m_cam_mat; ///<Camera matrix.
};
/**
Free moving Camera.
*/
class M3DFreeCam : public M3DCam
{
public:
void Init(EngineData *ed);
void CleanUp(void);
.
.
.
.
private:
hi_sint32 m_cam_ang; ///<Angle of rotation of camera w.r.t Y axis.
Vec3i m_dir; ///<Direction vector of movement.
};
/**
Base Engine class.
*/
class Engine : public EngineData
{
private:
M3DFreeCam m_cam;
.
.
.
}
/**
Initialize the game engine.
\return TRUE if success.
*/
BOOL Engine::Init(void)
{
BOOL res = TRUE;
EngineData::Init();
SetGameState((GSFunc)Engine::GS_Game, GS_GAME);
m_cam.Init(this); <<-----------CRASHES HERE
m_cam.MoveForward(10);
m_m3dengine.SelectCamera(&m_cam);
xit:
return res;
}
Here m_cam is a member variable in Engine. It is of type
M3DFreeCam(derived from MD3Cam). Init() is a virtual function. But when
I call m_cam.Init(this), the program crashes!
(Unhandled exception at 0x00f09f33 (pool.dll) in BREW_Emulator.exe:
0xC0000005: Access violation reading location 0x00000000.)
If I make m_cam a local variable(instead of member variable),
inside Engine::Init(), it works fine, no crashes. I wonder why this is
happening. Could anyone please explain this to me?
Thanks in advance.
#ifndef M3DCAMERA__H__
#define M3DCAMERA__H__
class M3DEngine;
/**
Micro3D Camera class.
*/
class M3DCam
{
public:
virtual void Init(EngineData *ed);
.
.
.
protected:
IMicro3D *m_pmicro3d; ///<Micro3D interface pointer.
Vec3i m_pos; ///<Position of the camera.
Vec3i m_target; ///<Target of the camera.
Vec3i m_up; ///<Camera up direction vector.
Atrans3i m_cam_mat; ///<Camera matrix.
};
/**
Free moving Camera.
*/
class M3DFreeCam : public M3DCam
{
public:
void Init(EngineData *ed);
void CleanUp(void);
.
.
.
.
private:
hi_sint32 m_cam_ang; ///<Angle of rotation of camera w.r.t Y axis.
Vec3i m_dir; ///<Direction vector of movement.
};
/**
Base Engine class.
*/
class Engine : public EngineData
{
private:
M3DFreeCam m_cam;
.
.
.
}
/**
Initialize the game engine.
\return TRUE if success.
*/
BOOL Engine::Init(void)
{
BOOL res = TRUE;
EngineData::Init();
SetGameState((GSFunc)Engine::GS_Game, GS_GAME);
m_cam.Init(this); <<-----------CRASHES HERE
m_cam.MoveForward(10);
m_m3dengine.SelectCamera(&m_cam);
xit:
return res;
}
Here m_cam is a member variable in Engine. It is of type
M3DFreeCam(derived from MD3Cam). Init() is a virtual function. But when
I call m_cam.Init(this), the program crashes!
(Unhandled exception at 0x00f09f33 (pool.dll) in BREW_Emulator.exe:
0xC0000005: Access violation reading location 0x00000000.)
If I make m_cam a local variable(instead of member variable),
inside Engine::Init(), it works fine, no crashes. I wonder why this is
happening. Could anyone please explain this to me?
Thanks in advance.