Page 1 of 1

window keeps exiting - first tutorial

Posted: Mon Jun 29, 2009 10:46 pm
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

Posted: Mon Jun 29, 2009 11:39 pm
by B@z
maybe you got an error when creating the window, and it called exit function?

try to debug it

Posted: Tue Jun 30, 2009 12:23 am
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;
}

Posted: Tue Jun 30, 2009 12:55 am
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).

Posted: Tue Jun 30, 2009 1:25 am
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.

Posted: Tue Jun 30, 2009 1:38 am
by Acki
are you sure this path is valid: "../../media/sydney.md2" ?!?!?
do you realy have the media files there !?!?!

Posted: Tue Jun 30, 2009 6:57 am
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.

Posted: Tue Jun 30, 2009 5:30 pm
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_ "??

Posted: Tue Jun 30, 2009 5:50 pm
by B@z
or just use DEBUG

Posted: Tue Jun 30, 2009 6:30 pm
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.

Posted: Tue Jun 30, 2009 7:35 pm
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...