device->run() crashes my game!

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
disanti
Posts: 367
Joined: Sat Jan 17, 2004 1:36 am
Location: California, US
Contact:

device->run() crashes my game!

Post by disanti »

Ok, I'm getting really mad about 0.5, I've narrowed my game crashes down to device->run(). When I comment that out of the while loop the game works fine except it never responds to windows. With that uncommented however, it doesn't work at all! It always crashes with the error "access violation" in the debugger. Why is this happening?

Is this happening because I recompiled Irrlicht.dll before using it?
I didn't make ANY changes to the engine at all before compiling it!
________
HEALTH SHOP
Last edited by disanti on Tue Feb 22, 2011 8:00 am, edited 1 time in total.
disanti
Posts: 367
Joined: Sat Jan 17, 2004 1:36 am
Location: California, US
Contact:

Post by disanti »

Ok, I changed the dll to Irrlicht.dll instead of my recompiled PSS4.dll and it is saying the error is withing Irrlicht.dll. What is up with this? Version 0.4.2 used to work just fine!
________
NCIS FORUM
Last edited by disanti on Tue Feb 22, 2011 8:00 am, edited 1 time in total.
level1

Post by level1 »

basically device::run() just does systemcalls to: PeekMessage, TranslateMessage and DispatchMessage, so its possible that
you have a problem in your event receiver function (if every thing works fine without the device-run() call)

have you rebuilt your app completely (msvc has that minimal rebuild option which tends to mix things up a little bit sometimes)

and if you recompiled irrlicht, did you set multithreaded support on?

on what system do you run your app?
thesmileman
Posts: 360
Joined: Tue Feb 10, 2004 2:20 am
Location: Lubbock, TX

Post by thesmileman »

post the code where it is crashing. Is it this code:

Code: Select all

while(irrDevice->run())


If that is the case most likely something is wrong in the creation of your Irrlicht device.
disanti
Posts: 367
Joined: Sat Jan 17, 2004 1:36 am
Location: California, US
Contact:

Post by disanti »

I'm using a class as a 'framework'.

Code: Select all

#ifndef _GAME_SPLASH___
#define _GAME_SPLASH___

#include <irrlicht.h>

class gamesplash
{
public:
	gamesplash();
	~gamesplash();

	void runsplash();
private:
	irr::IrrlichtDevice*		device;
	irr::video::IVideoDriver*	driver;
	irr::scene::ISceneManager*	smgr;

	bool splashrun;
};

#endif //_GAME_SPLASH___
The code of the class:

Code: Select all

#include "gamesplash.h"
#include "defines.h"

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

//make the camera object
scene::ICameraSceneNode* camera = 0;

//event receiver
class MyEventReceiver : public IEventReceiver
{
public:
	virtual bool OnEvent(SEvent event)
	{
		if (camera)
			return camera->OnEvent(event);

		return false;
	}
};

gamesplash::gamesplash()
{
	MyEventReceiver receiver;

	device =
		createDevice(EDT_DIRECTX8, dimension2d<s32>(GAME_RESX, GAME_RESY),
		GAME_DEPTH, GAME_FULLSCREEN, GAME_SHADOWS, &receiver);
	//set the device caption 
	device->setWindowCaption(GAME_TITLE);

	//driver
	driver = device->getVideoDriver();
	//scene manager
	smgr = device->getSceneManager();

	splashrun = true;
}

gamesplash::~gamesplash()
{
}

void gamesplash::runsplash()
{
	while(splashrun==true && device->run())
	{
		driver->beginScene(true, true, video::SColor(0,0,0,0));

		driver->endScene();
	}
}
Am i doing something wrong?

I've tried removing the splashrun==true && but that didn't help at all :P!
________
GLOBAL HYBRID COOPERATION
Last edited by disanti on Tue Feb 22, 2011 8:01 am, edited 1 time in total.
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Post by niko »

Maybe you call run() after you closed or deleted the device?
Guest

Post by Guest »

Code: Select all

class MyEventReceiver : public irr::IEventReceiver{
  public:

    // ATTENTION HERE
    bool *end;
    
    virtual bool OnEvent(irr::SEvent event){
      if(event.EventType==irr::EET_KEY_INPUT_EVENT){
        if(event.KeyInput.Key==irr::KEY_ESCAPE && 
!event.KeyInput.PressedDown){
          *end=true;
          return true;
        }
      }
      /*
      .... otehr event stuff
      */ 
      
      return false;
    }
  };
and in your application:

Code: Select all


// if this variable is true we end the gameloop
bool EndTheGame=false;

// create the receiver
MyEventReceiver receiver;
// let the receiver know what variable 'receiver.end' points to
receiver.end=&EndTheGame;

// create the IRRDevice
IrrlichtDevice* device=createDevice(video::EDT_DIRECTX8,core::dimension2d<s32>(640, 480),32, false, true, &receiver);

// do some usefull stuff ... init etc.

// gameloop
while ( !EndTheGame && device->run() )
{

// ...

}

device->closeDevice();

if you call device->closeDevice() in the receiver it will close the window during the game loop, hence leave the irrlicht subsystem in an undefined state.... (or something like that)

i hope this helps

level1
Gonosz
Posts: 24
Joined: Wed Oct 29, 2003 4:21 pm
Location: Hungary (one joke and you're dead)

Post by Gonosz »

The eventreceiver is declared in the constructor, and the pointer is passed to Irrlicht, which may crash the game when the first event comes by.

Edit:

If I were you, I'd try to get rid of the camera global variable. To do this, inherit the gamesplash class from IEventReceiver and place the OnEvent in it. This way you can put the camera into the class. This is just an idea, first make it work :)

Gonosz
disanti
Posts: 367
Joined: Sat Jan 17, 2004 1:36 am
Location: California, US
Contact:

Post by disanti »

Thanks everyone!!! It was the Event Receiver. Oh well, I can do without it! :P I use DirectInput.
________
Mercedes-Benz S-Class
Post Reply