Crash on IrrlichtDevice::run()

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
eezstreet
Posts: 6
Joined: Wed Feb 13, 2013 3:50 am

Crash on IrrlichtDevice::run()

Post by eezstreet »

Hello there! I am a bit new to this community, and I do like the features of this engine. I look forward to using it more in-depth. :)
I seem to be having an issue with something very simple/basic. My main game loop appears to be crashing on IrrlichtDevice::run() after I hit the exit button on the app (when not in fullscreen) or by hitting alt+f4. I have most of my stuff that involves the IrrlichtDevice and IrrlichtDriver in a class, which has a singleton setup. Quite simply:

Code: Select all

 
// the entry point for any Windows program
int main()
{
    // Setup main game class
    GameClass::GetSingleton();
 
    // Now instantiate the renderer class
    Renderer::GetSingleton();
 
    // enter the main loop:
    MainGameLoop();
 
    // Kill game process
    GentleKillProcess();
    return 0;
}
 
The main loop looks something like this:

Code: Select all

 
void MainGameLoop()
{
 
    while(Renderer::GetSingleton()->RunDevice() && Renderer::GetSingleton()->GetDriver())
    {
        GameClass::GetSingleton()->RunFrame();
    }
}
 
The RunDevice method of the Renderer class is just "return device->run();" more or less. If it helps, I can also supply the bits of GameClass::RunFrame where the Renderer class gets involved:

Code: Select all

 
void Renderer::DrawAll(void)
{
    if(device->isWindowActive())
    {
        device->getTimer()->tick();
        driver->beginScene(true, true, SColor(255, 255, 255, 0));
 
        sceneManager->drawAll();
        gui->drawAll();
        driver->endScene();
    }
}
 
I've been receiving crashes in Renderer::RunDevice after I close the game window, and it never reaches GentleKillProcess();. A friend of mine and I were spending quite a bit of time on Teamviewer and couldn't come up with any kind of sensible solution. Could anyone here lend a hand? Thanks!
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Crash on IrrlichtDevice::run()

Post by hybrid »

I'd say you somewhere drop() the device while still accessing its methods later on. A debugger would probably help to see the state of the device at crash.
eezstreet
Posts: 6
Joined: Wed Feb 13, 2013 3:50 am

Re: Crash on IrrlichtDevice::run()

Post by eezstreet »

Hi,
No, the crash occurs before the code has a chance to even reach the device->drop or device->closeDevice. That all occurs in the deconstructor of my Renderer class, and the singleton for it gets destroyed in GentleKillProcess()

Thanks for the reply though.

EDIT: If it helps, it sometimes also crashes at the end of mainCRTStartup.
polylux
Posts: 267
Joined: Thu Aug 27, 2009 12:39 pm
Location: EU

Re: Crash on IrrlichtDevice::run()

Post by polylux »

As hybrid already suggests, don't be scared and use your debugger. It'll track down the issue in no time. With the info you provide there's no way to give better advise.
beer->setMotivationCallback(this);
eezstreet
Posts: 6
Joined: Wed Feb 13, 2013 3:50 am

Re: Crash on IrrlichtDevice::run()

Post by eezstreet »

Hello,
I've been debugging for hours and haven't found any useful information. At this point, I'm running the exact same code as the example (with a similar folder structure as well), and I'm about to rip my hair out over this annoying issue. I've stripped my code down to a simple main function:

Code: Select all

 
#include <irrlicht.h>
//#ifdef _WIN32
//#include <Windows.h>
//#endif
 
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
 
#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif
 
int main()
{
    IrrlichtDevice *device =
        createDevice( video::EDT_SOFTWARE, dimension2d<u32>(640, 480), 16,
            false, false, false, 0);
 
    if (!device)
        return 1;
 
    device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");
 
    IVideoDriver* driver = device->getVideoDriver();
    ISceneManager* smgr = device->getSceneManager();
    IGUIEnvironment* guienv = device->getGUIEnvironment();
 
    guienv->addStaticText(L"Hello World! This is the Irrlicht Software renderer!",
        rect<s32>(10,10,260,22), true);
 
    while(device->run())
    {
        driver->beginScene(true, true, SColor(255,100,101,140));
 
        smgr->drawAll();
        guienv->drawAll();
 
        driver->endScene();
    }
    device->drop();
 
    return 0;
}
 
Even the examples, when modified to look exactly the same as this, compile and run just fine, and have no issues. Yet whenever I replicate the same scenario to a T (copying all the project settings in VS one by one so that it's more or less identical to the example), it refuses to close without giving so much as an error.
At this point, I'm half-tempted to just frankenstein the bits I have of my engine into the example and see where that leads me.
gerdb
Posts: 194
Joined: Wed Dec 02, 2009 8:21 pm
Location: Dresden, Germany

Re: Crash on IrrlichtDevice::run()

Post by gerdb »

Hi,

you posted some valid code that has nothing todo with your problem!

Why?

You tell you have problems but dont show any code so we cant help, but you annoy us having problems.

Sry but that sucks bigtime.

EDIT: to everyone else: best wishes for the new year and happy coding.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Crash on IrrlichtDevice::run()

Post by CuteAlien »

That definitely does not sound like a code problem (above code looks correct). Check the console-log window. Maybe it says for example something about another dll-version which is used than the one you expect it to use.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply