I'm trying to make a kind of game framework fully OOP so i can use it in my future games without having any problem.
The major problem is when i try to pass pointers between each classes, not any pointer, the IrrlichtDevice only, I dont know why, it compiles perfectly but the application crashes instantly after execution.
Heres a bit of code :
Manager.h
Code: Select all
#ifndef _MANAGER_H
#define _MANAGER_H
#include <irrlicht.h>
#include <stdlib.h>
#include <stdio.h>
#include "CReceveur.h"
#include "CEtatdeJeu.h"
#define RESX 800
#define RESY 600
#define BITS 032
#define SCRN 000
#define STBF 000
#define VSNC 000
#define ANTA 000
class CManager
{
public :
CManager();
virtual ~CManager();
irr::IrrlichtDevice* getDevice();
irr::video::IVideoDriver* getVideo();
irr::scene::ISceneManager* getSmgr();
irr::gui::IGUIEnvironment* getGUIe();
void InitialiserDevice(void);
void LireConfig(void);
bool RenduTR(void);
private :
irr::IrrlichtDevice* device;
irr::SIrrlichtCreationParameters param;
irr::video::IVideoDriver* driver;
irr::scene::ISceneManager* smgr;
irr::gui::IGUIEnvironment* gui;
CReceveur Receveur;
CEtatdeJeu* JeuRendu;
FILE* Config;
};
#endif
Code: Select all
#include "CManager.h"
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
CManager::CManager()
{
Config = NULL;
LireConfig();
JeuRendu = new CEtatdeJeu(device);
}
CManager::~CManager()
{
}
void CManager::InitialiserDevice(void)
{
device = createDeviceEx(param);
device->setWindowCaption(L"GAMEFRAMEWORK-IYAD, FPS-1");
device->setEventReceiver(&Receveur);
driver = device->getVideoDriver();
smgr = device->getSceneManager();
gui = device->getGUIEnvironment();
RenduTR();
}
bool CManager::RenduTR(void)
{
while(device->run())
{
driver->beginScene(true, true,
SColor(0,200,200,200));
JeuRendu->ToutModes();
smgr->drawAll();
gui->drawAll();
driver->endScene();
}
device->drop();
return false;
}
void CManager::LireConfig(void)
{
Config = fopen("Configuration.txt", "r");
if (Config != NULL)
{
//Load paramaters for the graphics
fclose(Config);
}
else
{
param.DriverType = EDT_OPENGL;
param.WindowSize = dimension2d<s32>(
RESX,
RESY);
param.Bits = BITS;
param.Fullscreen = SCRN;
param.Stencilbuffer = STBF;
param.Vsync = VSNC;
param.AntiAlias = ANTA;
}
}
IrrlichtDevice* CManager::getDevice()
{return device;}
IVideoDriver* CManager::getVideo()
{return driver;}
ISceneManager* CManager::getSmgr()
{return smgr;}
IGUIEnvironment* CManager::getGUIe()
{return gui;}
Code: Select all
#ifndef ETATDEJEU_H
#define ETATDEJEU_H
#include <irrlicht.h>
#include "CMenu.h"
#define MODE1 1
#define MODE2 2
class CEtatdeJeu
{
public :
CEtatdeJeu(irr::IrrlichtDevice* deviceX);
virtual ~CEtatdeJeu();
void ToutModes(void);
void Mode1Calc(void);
void Mode2Calc(void);
irr::IrrlichtDevice* retDev(void);
private :
int Mode;
irr::IrrlichtDevice* deviceNEW;
//CMenu* Menu;
};
#endif
Code: Select all
#include "CEtatdeJeu.h"
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
CEtatdeJeu::CEtatdeJeu(IrrlichtDevice* deviceX)
{
Mode = MODE1;
deviceNEW = deviceX;
/*
HERES THE PROBLEM : i try to call a function that uses the device and it crashes. Like that it open perfectly, but when i add for example
deviceNEW->setWindowCaption(L"BUG!"); it makes me a fatal error
*/
//Menu = new CMenu(deviceNEW);
}
CEtatdeJeu::~CEtatdeJeu()
{
}
void CEtatdeJeu::ToutModes(void)
{
if (Mode == MODE1)
{
}
if (Mode == MODE2)
{
}
}
void CEtatdeJeu::Mode1Calc(void)
{
}
void CEtatdeJeu::Mode2Calc(void)
{
}
IrrlichtDevice* CEtatdeJeu::retDev(void)
{return deviceNEW;}
Thanks for your replies.