run time error

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
Yustme
Posts: 107
Joined: Sat Dec 01, 2007 10:50 pm

run time error

Post by Yustme »

Hi,

I'm using the event receive handler of Halifax and a code snippet of dudeMaN beginners tutorial.

Everything compiles fine but at runtime it generates this exception:

Unhandled exception at 0x00411a66 in Game.exe: 0xC0000005: Access violation reading location 0x00000001.

And its pointing to this line:

switch (event.EventType)

In file: CIrrEventReceiver.cpp


This is my main:

Code: Select all


int main(int argc, char **argv)
{
	IrrlichtDevice* device = createDevice(EDT_OPENGL, core::dimension2d<s32>(640,480));
	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->getSceneManager();

	CIrrEventReceiver* rv = new CIrrEventReceiver();
	device->setEventReceiver(rv); 

	for(int x=0; x<irr::KEY_KEY_CODES_COUNT; x++) keys[x] = false;

	ISceneNode* cube = smgr->addCubeSceneNode();
	cube->setPosition(vector3df(0,0,5)); 

	while(device->run() && rv->isKeyUp(KEY_UP))
	{
		/*if(keys[KEY_KEY_W]) 
		{
			cube->setPosition(cube->getPosition()+vector3df(0,0,5));
		}*/

		driver->beginScene(true, true, video::SColor(255,0,0,255));
		smgr->drawAll();
		driver->endScene(); 
	}
   
    return 0;
}

I'm using visual studio 2005 as IDE.

What am i doing wrong guys?

Thanks in advance!
ultran00b
Posts: 35
Joined: Tue Oct 30, 2007 3:30 pm

Post by ultran00b »

This line I believe to be the problem:

Code: Select all

CIrrEventReceiver* rv = new CIrrEventReceiver();
I don't think that the programmer has to allocate his event receiver off the heap... In fact, I don't even think that your event receiver has to be a pointer. I usually use something like this, and it works for me (BTW ignore the parameter in the first line of code):

Code: Select all

CIrrEventReceiver eventReceiver(device);
device->setEventReceiver(&eventReceiver);
Hope it helps.
Use the debugger, young Skywalker...
Yustme
Posts: 107
Joined: Sat Dec 01, 2007 10:50 pm

Post by Yustme »

Hi,

I used the code sample of Halifax. He used a pointer in it. But both way's work.

I managed to fix the problem just a minute ago by upgrading to 1.4.

Somehow i overlooked the irrlicht version 1.4 :oops:

Thank you very much!

Yustme
Post Reply