window keeps exiting - first tutorial

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
richard3014@hotmail.com
Posts: 3
Joined: Mon Jun 29, 2009 10:44 pm

window keeps exiting - first tutorial

Post by richard3014@hotmail.com »

I got my code to compile and everything, but when I click on the exe files it opens and exits the window pretty fast. I have tried cin.get() or system(pause), but I still have the same problem. Any help will be appreciated.

Thanks,

Ricardo
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post by B@z »

maybe you got an error when creating the window, and it called exit function?

try to debug it
Image
Image
richard3014@hotmail.com
Posts: 3
Joined: Mon Jun 29, 2009 10:44 pm

Post by richard3014@hotmail.com »

I dont get it. It is exactly the same code as the tutorial webpage:

I do not know why does it keep exiting! =s

This is the code:

#include <irrlicht.h>



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()
{
cin.get();
IrrlichtDevice *device =
#ifdef _IRR_OSX_PLATFORM_
createDevice( video::EDT_OPENGL, dimension2d<s32>(640, 480), 16,
false, false, false, 0);
#else
createDevice( video::EDT_SOFTWARE, dimension2d<s32>(640, 480), 16,
false, false, false, 0);
#endif
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);

IAnimatedMesh* mesh = smgr->getMesh("../../media/sydney.md2");
if (!mesh)
return 1;
IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );


if (node)
{
node->setMaterialFlag(EMF_LIGHTING, false);
node->setMD2Animation(scene::EMAT_STAND);
node->setMaterialTexture( 0, driver->getTexture("../../media/sydney.bmp") );
}

smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));

while(device->run())
{

driver->beginScene(true, true, SColor(255,100,101,140));

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

driver->endScene();
}

device->drop();

return 0;
}
CuteAlien
Admin
Posts: 9721
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Are you sure it really starts the application? Check the build-messages, are there any errors?
Otherwise you might want to step through it with the debugger (set a breakpoint in the first line).
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
richard3014@hotmail.com
Posts: 3
Joined: Mon Jun 29, 2009 10:44 pm

Post by richard3014@hotmail.com »

yes, the application does start...it is pretty strange..=s
When I comment out this line:

#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")

The black window stays, but the other window console never appears.
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

are you sure this path is valid: "../../media/sydney.md2" ?!?!?
do you realy have the media files there !?!?!
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Probably the Irrlicht.dll (or some CRT dll or similar) is missing, which causes the program to close without even starting. That would prevent the cin stuff etc as well.
abhishekdey1985
Posts: 102
Joined: Sat Jan 17, 2009 4:33 am
Location: Pune
Contact:

Post by abhishekdey1985 »

i think ur device is not getting created. Insert a cout statement just before

if(!device)
return 0;

and after. Jus check!!

and if ur using Windows...then why u need "_ifdef _IRR_OSX_PLATFORM_ "??
I work on "The Best Real-Time 3D Engine"
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post by B@z »

or just use DEBUG
Image
Image
CuteAlien
Admin
Posts: 9721
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Well, if it actually quits in the application then most likely for the reason Acki mentioned - it doesn't find the media files.

But just set a breakpoint in the first line, start in debug and step through. If you are using an IDE (and I suppose so) than that is easy to do. If you tell us which IDE we might even be able to tell you exactly how to do that.
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
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

yes, the missing media files are the most common error for this...
but what makes me curious is that he says that there is just the black console:
richard3014@hotmail.com wrote:When I comment out this line:

#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")

The black window stays, but the other window console never appears.
but the console should tell what happened... :shock:
maybe try it without that cin.get() (what ever it is for in this code ???) and look what the console tells you...
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Post Reply