a runtime error

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
hdalin
Posts: 3
Joined: Tue Sep 01, 2009 6:57 pm

a runtime error

Post by hdalin »

Hi everyone ... i'm kind of new to irrlicht and i wanted to start a small project, but i already have a problem.

I have the next three files:

main.cpp

Code: Select all

#include <irrlicht.h>
#include "game.h"
using namespace irr;

int main()
{
       ggame *game;
       game -> init();
       game -> run();
       return 0;
}
game.h

Code: Select all

#ifndef _GMAE_H_
#define _GAME_H_
#include <irrlicht.h>
using namespace irr;

class ggame
{
    struct ssettings
    {
        bool fullscreen;
        int scrHeight;
        int scrWidth;
        int scrBPP;
    } settings;
    IrrlichtDevice *device;
    video::IVideoDriver *driver;
    scene::ISceneManager *smgr;
    io::IFileSystem *fileSys;
    gui::ICursorControl *cursor;

public:
    void init();

    // getting the settings ... those that are there so far
    bool isFulscreen();
    int getScrHeight();
    int getScrWidth();
    int getScrBPP();

    void run();

};
#endif
game.cpp

Code: Select all

#include "game.h"
#include <irrlicht.h>
using namespace std;

void ggame::init()
{
    device = createDevice(video::EDT_OPENGL,
                            core::dimension2d<u32>(640,480));
    driver = device -> getVideoDriver();
    smgr = device -> getSceneManager();
    fileSys = device -> getFileSystem();
    cursor = device -> getCursorControl();

}
bool ggame::isFulscreen()
{
    return settings.fullscreen;
}
int ggame::getScrHeight()
{
    return settings.scrHeight;
}
int ggame::getScrWidth()
{
    return settings.scrWidth;
}
int ggame::getScrBPP()
{
    return settings.scrBPP;
}
void ggame::run()
{
    device -> setWindowCaption(L"Title");
    smgr->addCameraSceneNodeFPS();
    while(device->run() && driver)
    {
        driver->beginScene(true, true, video::SColor(255,0,0,255));
        smgr->drawAll();
        driver->endScene();
    }
    device->drop();
}
Now ... for some unknown reason, in game.cpp, the device is created, getVideoDriver() works fine, but at smgr = device -> getSceneManager(); i get a runtime error and codeblock only says that "process is terminated with status -1073741819".

The codeblocks debugger doesn't seem to point at the problem, i only found it by using the exit function.

Can anyone help me and explain what's wrong with it?
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Re: a runtime error

Post by greenya »

hdalin wrote: main.cpp

Code: Select all

#include <irrlicht.h>
#include "game.h"
using namespace irr;

int main()
{
       ggame *game;
       game -> init();
       game -> run();
       return 0;
}
This should be :

Code: Select all

#include <irrlicht.h>
#include "game.h"
using namespace irr;

int main()
{
       ggame *game = new ggame();
       game -> init();
       game -> run();
       delete ggame;
       return 0;
}
hdalin
Posts: 3
Joined: Tue Sep 01, 2009 6:57 pm

Post by hdalin »

:oops: Oops, i wasn't carefull enough. Thanks for the help.

P.S.: It's delete game, not delete ggame (thought you might want to know).
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

In some cases, it would be smarter to write...

Code: Select all

int main ()
{
  ggame game;
  game.init();
  game.run();
  return 0;
}
This avoids an unnecessary heap allocation and avoids potential leakage when if exception is thrown. In this case it isn't a huge deal, but it is a good idea to think about these things when writing code.

Travis
Post Reply