Irr, DevC. or coding problem?

Discuss about anything related to the Irrlicht Engine, or read announcements about any significant features or usage changes.
Post Reply
Anteater

Irr, DevC. or coding problem?

Post by Anteater »

OK, I've got my basic game working, and I'm working on the title screen.
Each level is a .exe file, so the title screen just starts the program when the user presses "START." The problem is that it causes the first level to have an illegal operation; however, when the first level is run by itself, it runs fine. Odd.
The code:

Code: Select all

// (C) 2005 Decapitation Games
#include <irrlicht.h>
#include <windows.h>
#include <mmsystem.h>
#include <stdio.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
int main()
{
IrrlichtDevice *deviceIrr = createDevice(video::EDT_OPENGL, core::dimension2d<s32>(640, 480), 32, false, false, false, 0);
printf (".");
IGUIEnvironment* guienv = deviceIrr->getGUIEnvironment();
printf (".");
IVideoDriver* driver = deviceIrr->getVideoDriver();
printf (".");
ISceneManager* smgr = deviceIrr->getSceneManager();
printf (".");
mciSendString("play media/mid0.mid",NULL,0,NULL);
printf (".\n");
//caption
deviceIrr->setWindowCaption (L"(C) 2005 Decapitation Games");
//splash screen
video:: ITexture* splash1 = driver->getTexture("media/splash.jpg");
//buttons are added
guienv->addButton (rect<s32>(5,60,105,635),0,102,L"LOAD");
guienv->addButton (rect<s32>(5,5,105,55),0,101,L"START");
class EventRGUI1 : public IEventReceiver
{
public:
virtual bool OnEvent(SEvent event)
{
if (event.EventType == EET_GUI_EVENT)
{
s32 id = event.GUIEvent.Caller->getID();
switch (event.GUIEvent.EventType)
{
case EGET_BUTTON_CLICKED:
if (id == 102)
{
}
if (id == 101)
{
ShellExecute(NULL,NULL,"../L1/Eric 3_L1.exe",NULL,NULL,SW_SHOW);
mciSendString ("stop media/mid0.mid",NULL,0,NULL);
return true;
}
break;
}
}
return false;
}
};
EventRGUI1 receiver1;
deviceIrr->setEventReceiver(&receiver1);
//run, stupid
while (deviceIrr->run())
{
driver->draw2DImage(splash1, core::position2d<s32>(0,0),
core::rect<s32>(0, 0, 640, 480), 0,
video::SColor(1, 255, 255, 255), true);
smgr->drawAll();
guienv->drawAll();
driver->endScene();
}
deviceIrr->drop();
return 0;
}
Anything invlolving the name of the game has been removed.
(Oh, yeah; almost forgot. If someone does help, they get in the "special thnx" in the credits :D )
Anteater

This is strange!

Post by Anteater »

Ok, I don't think it's a coding error because I even tried using Game Maker
http://www.gamemaker.nl to do the "execute the first level exe" part of the program but it still causes an error. Also, the ilegal operation happens when Irrlicht creates the device. :?: :?:
Anteater

This is strange!

Post by Anteater »

Ok, I don't think it's a coding error because I even tried using Game Maker
http://www.gamemaker.nl to do the "execute the first level exe" part of the program but it still causes an error. Also, the ilegal operation happens when Irrlicht creates the device. :?: :?:
jox
Bug Slayer
Posts: 726
Joined: Thu Apr 22, 2004 6:55 pm
Location: Germany

Post by jox »

I'm not sure about your problem. But I noticed your main loop has no beginScene.

Code: Select all

driver->beginScene(true, true, video::SColor(255, 128, 128, 128));
Also your ShellExecute has no "lpOperation" parameter.

Code: Select all

ShellExecute(NULL,"open","../Irrlicht/irrlicht-0.9/bin/VisualStudio/01.HelloWorld_cs.exe",NULL,NULL,SW_SHOW);
(the "open")

What happens if you run your loader in Software mode?
It is like it is. And because it is like it is, things are like they are.
Anteater

Post by Anteater »

Well, I tried doing all of that but it still doesn't work. By the way, I don't know if this makes any difference but all the pointer names (like "guienv")
are the same for both the shell and level1 executable.
Also, like I said, I even tried using Game Maker to make the first level, but the same EXACT problem did the same EXACT thing.
Guest

Post by Guest »

I don't know what gamemaker does, but are you sure the error is IN createdevice, and not AFTER createdevice?

You have to understand that printf is buffered I/O, and won't send anything to the console until there's a \n to print.

If createdevice fails, because for example it can't allocate a buffer, dereferencing the "device" pointer will cause a crash.
Anteater

Post by Anteater »

If createdevice fails, because for example it can't allocate a buffer, dereferencing the "device" pointer will cause a crash.
Ok, what does that mean? (I'm quite NooBish :oops: ) Oh, and by the way, game maker's web site is www.gamemaker.nl. Also, I tried using the title screen program to run another Irrlicht app (the terrain example) but the same EXACT problem occurs. One other thing: Just after the device is created, the GUI Environment, scene, dirver pointers, etc are created in the first level exe.
Guest

Post by Guest »

dereferencing a pointer:

Code: Select all

    device->something
If device is not a valid pointer (i.e. it is 0), then the above expression will crash your program.
And the buffered output will not be printed to the console.

I've now had a quick look at the gamemaker site - and it seems to be a standalone tool, it does not use irrlicht for anything.
So does your launcher crash or is it only the game level which crashes?

One thing I can imagine happening is that Direct3D or DirectDraw cannot not be used by multiple programs at a time. You could try switching your launcher to the software renderer.

Or your could try placing the shellexecute stuff outside the event receiver, then you can also close the device while you don't need it.

Something like:

event receiver:

Code: Select all

  case EGET_BUTTON_CLICKED: 
      clickedbuttonid=id;
      return true;
main:

Code: Select all

ExitProgram=false;
while(!ExitProgram) {
 device =  OpenDevice(...);
 if(device==0)
  exit(1);   // panic: can't open the irrlicht device for displaying the launcher
 ....
 clickedbuttonid=0;
 while(device->Run() && clickedbuttonid==0) {
   ...
    
 }
 device->Close();
 switch(clickedbuttonid) {
   case 101:
    ShellExecute(NULL,NULL,"../L1/Eric 3_L1.exe",NULL,NULL,SW_SHOW);
    mciSendString ("stop media/mid0.mid",NULL,0,NULL);
     break;
   case 102:
     break;
   case 199: // or whatever ID you give to the exit button
     ExitProgram=true;
     break;
 }
}
Post Reply