I am new to Irrlicht (1.8.1) and followed the tutorials. Actually it bothered me to keep working on just the main function, so I tried a little something with my own class for a GUI, with init/run/close methods to do the actual job. Problem is: using my run() in the main makes it crash at runtime (while not if called in the end of init()), and removing the event management makes it work again too, which I definitely can't. Here is the technical part (CMake aside), reduced to the minimum:
Code: Select all
#include <irrlicht/irrlicht.h>
using namespace irr;
class MyEventReceiver : public IEventReceiver {
public:
virtual bool OnEvent(const SEvent& event) {
return false;
}
};
class MyGUI {
private:
IrrlichtDevice* _device;
video::IVideoDriver* _driver;
public:
MyGUI();
~MyGUI();
void init();
void run();
void close();
};
MyGUI::MyGUI() :
_device(0),
_driver(0) {
init();
}
MyGUI::~MyGUI() {
close();
}
void MyGUI::init() {
_device = createDevice(video::EDT_OPENGL, core::dimension2du(800, 600), 32);
_device->setWindowCaption(L"A simple GUI to test");
_device->setResizable(false);
_driver = _device->getVideoDriver();
MyEventReceiver receiver;
_device->setEventReceiver(&receiver);
}
void MyGUI::run() {
while (_device->run() && _driver) {
_driver->beginScene(true, true, video::SColor(0, 200, 200, 200));
_device->getGUIEnvironment()->drawAll();
_driver->endScene();
}
}
void MyGUI::close() {
_device->drop();
}
int main(int, char**) {
MyGUI engine;
engine.run();
return 0;
}