Program window closes when calling Video device

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
headfonez
Posts: 12
Joined: Wed Oct 31, 2007 2:04 pm

Program window closes when calling Video device

Post by headfonez »

When I call the irr video device command, the program closes.

Code: Select all

using namespace irr;

using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;


#pragma comment(lib, "Irrlicht.lib")
 

int main()
{
   	IrrlichtDevice *device =
		createDevice(EDT_SOFTWARE, dimension2d<s32>(640, 480), 16,
			false, false, false, 0);   //here is where my program goes down.

	return 0;
}

Any idea why this may be happening. My video drivers are pretty standard if not advanced.
ultran00b
Posts: 35
Joined: Tue Oct 30, 2007 3:30 pm

Post by ultran00b »

You don't have a mainloop!!! "return 0" is where your program goes down.

Code: Select all

    while(device->run())
    {
        driver->beginScene(true, true, SColor(0,200,200,200));

        smgr->drawAll();
        guienv->drawAll();

        driver->endScene();
    }

    device->drop();

    return 0;
Stick the above code after you create your device. It's what's called a mainloop. It keeps your program running until you close it.[/code]
Use the debugger, young Skywalker...
headfonez
Posts: 12
Joined: Wed Oct 31, 2007 2:04 pm

Post by headfonez »

Thanks, I've added the code below, and what happens is, command prompt type programm window briefly opens, and then abruptly shuts down. I imagiane that a graphic window is supposed to appear, but it does not. Here is the code below:

Code: Select all

#include <irrlicht/irrlicht.h>
#include <stdio.h>  /* header file  */
#include <stdlib.h>

using namespace irr;

using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

#pragma comment(lib, "Irrlicht.lib")
 

int main()
{
    system("PAUSE");

	IrrlichtDevice *device =
		createDevice(EDT_SOFTWARE, dimension2d<s32>(640, 480), 16,
			false, false, false, 0);

	
	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->getSceneManager();
	IGUIEnvironment* guienv = device->getGUIEnvironment();

     while(device->run()) 
    { 
        driver->beginScene(true, true, SColor(0,200,200,200)); 

        smgr->drawAll(); 
        guienv->drawAll(); 

        driver->endScene(); 
    } 

    device->drop(); 

    return 0;


}
ultran00b
Posts: 35
Joined: Tue Oct 30, 2007 3:30 pm

Post by ultran00b »

Do you have irrlicht.dll in the same directory as your built executable? Does your compiler say something like, "warning: ignoring #pragma comment"? I compiled your code exactly how it was, and it worked fine.
Use the debugger, young Skywalker...
headfonez
Posts: 12
Joined: Wed Oct 31, 2007 2:04 pm

Post by headfonez »

ultran00b wrote:Do you have irrlicht.dll in the same directory as your built executable?
That worked! Thanks, you're a life saver. Looks like you're not a noob after all. Noobs helping noobs, thats what its all about.
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

That code is fine. This line is interesting:

Code: Select all

#include <irrlicht/irrlicht.h> 
The irrlicht.h is the SDK is in include/irrlicht.h, not foo/irrlicht/irrlicht.h. What have you done to your SDK / build environment to require including it from irrlicht/irrlicht.h? I want to be sure that the dll/libs that you're linking with match the includes that you're using, as this is a very common cause of problems.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Post Reply