Program crashes when I use an EventReceiver

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
nathanf534
Posts: 199
Joined: Tue Dec 09, 2008 2:55 am

Program crashes when I use an EventReceiver

Post by nathanf534 »

When I add an event receiver to my code, it crashes (its the MastEventReceiver class posted on our forums)

Code: Select all

int main(){
	cout<<"starting"<<endl;
	EventReceiver* er;
	cout<<er<<endl;
	IrrlichtDevice *device = createDevice(EDT_OPENGL, dimension2d<u32>(800,500), 32,false, false, true,er);//if I set the event receiver here, it crashes on this line

	//device->setEventReceiver(er);//if I set the event receiver here, it crashes at the indicated line below
	cout<<"end init"<<endl;
	NewtonWorld *nWorld = NewtonCreate();
	NewtonSetSolverModel(nWorld,0);
	device->setWindowCaption(L"Basic Collision Detection with Newton GD");
	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->getSceneManager();
	SObject sphere;
	SObject cube;
	NewtonCube* nCube;
	nCube->mesh = smgr->getMesh("C:/Models/testCube.b3d");//CRASHES HERE
	nCube->node = smgr->addMeshSceneNode(nCube->mesh);
	nCube->node->setPosition(vector3df(0,3,0));
	nCube->node->getMaterial(0).EmissiveColor.set(255,255,255,255);
	nCube->collision = NewtonCreateBox(nWorld, 2, 2, 2, NULL,NULL);
	nCube->gravity=-4;
	nCube->body = NewtonCreateBody(nWorld, nCube->collision);
	matrix4 mat;
	mat.setTranslation(vector3df(0,5,0));
	NewtonBodySetMatrix(nCube->body, &mat.M[0]);
	NewtonBodySetUserData(nCube->body,nCube);
	NewtonBodySetMassMatrix(nCube->body,10,150,150,150);
	NewtonBodySetTransformCallback(nCube->body,callbackTransform);
	NewtonBodySetForceAndTorqueCallback(nCube->body, ApplyForceAndTorqueEvent);
while(signatureEmpty){cout<<wittyComment();}
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Re: Program crashes when I use an EventReceiver

Post by Acki »

EventReceiver* er;
this creates an undefined pointer (to garbage) !!! :roll:

try this:

Code: Select all

EventReceiver er;
   IrrlichtDevice *device = createDevice(EDT_OPENGL, dimension2d<u32>(800,500), 32,false, false, true, &er);
but this won't work too, unless you create your own receiver class !!! :roll:
the tutorials are showing this pretty well !!! :lol:
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
nathanf534
Posts: 199
Joined: Tue Dec 09, 2008 2:55 am

Post by nathanf534 »

I changed the code you said, but it still does the same thing. Also, what do you mean by it won't work unless I create my own receiver class? I'm using the MastEventReceiver (just renamed it to EventReceiver).
while(signatureEmpty){cout<<wittyComment();}
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

then tell us where it crashes, how it crashes and the error message you got...
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
nathanf534
Posts: 199
Joined: Tue Dec 09, 2008 2:55 am

Post by nathanf534 »

I put where it crashes in the comments of the code. When it crashes, I just get the windows error message "IrrlichtGame.exe has stopped working", and it exits.
while(signatureEmpty){cout<<wittyComment();}
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

you're using this receiver: http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=21657 ???
creating and passing it to the device like I described works like expected, but you'll have to update the onEvent function declaration, because it's out of date... ;)
also if you don't change the onEvent declaration it should not compile !!! :shock:
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
nathanf534
Posts: 199
Joined: Tue Dec 09, 2008 2:55 am

Post by nathanf534 »

yea, I updated the OnEvent method, and it compiles fine. It just crashes while it's running.
while(signatureEmpty){cout<<wittyComment();}
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

for me it runns like a charm !!!
I bet the error is somewhere else in your code..
also this tells me that it's not the receiver himselve:

Code: Select all

//device->setEventReceiver(er);//if I set the event receiver here, it crashes at the indicated line below 
...
nCube->mesh = smgr->getMesh("C:/Models/testCube.b3d");//CRASHES HERE 
Last edited by Acki on Mon Feb 15, 2010 10:28 pm, edited 1 time in total.
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
nathanf534
Posts: 199
Joined: Tue Dec 09, 2008 2:55 am

Post by nathanf534 »

hmm... I changed

Code: Select all

NewtonCube *nCube;
to

Code: Select all

NewtonCube nCube;
(and changed other parts of the code to make that work) and it seems to be working now. I guess that just didn't show up until I tried to add an eventReceiver... wierd :roll:

Thanks for helping me :D
while(signatureEmpty){cout<<wittyComment();}
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

aha, of course the same like with the receiver

Code: Select all

   NewtonCube* nCube;
this creates an undefined pointer (to garbage), too !!! :lol:
maybe take a deeper look on pointers... :roll:
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
nathanf534
Posts: 199
Joined: Tue Dec 09, 2008 2:55 am

Post by nathanf534 »

I always thought

Code: Select all

Object name;
and

Code: Select all

Object* name;
were the exact same except that the 2nd returns a pointer to the object... but I guess I'm wrong. Ill go look that up.
while(signatureEmpty){cout<<wittyComment();}
Zeus
Posts: 24
Joined: Sun Dec 13, 2009 1:03 pm
Location: Germany :P

Post by Zeus »

you realy should learn something about pointers and references ...

http://www.cplusplus.com/doc/tutorial/pointers/
http://www.augustcouncil.com/~tgibson/tutorial/ptr.html

your object reference has to exists if you want to use it by pointers cause the pointer himself is no valid object ...

regards zeus
nathanf534
Posts: 199
Joined: Tue Dec 09, 2008 2:55 am

Post by nathanf534 »

Thanks, those explained a lot to me.
while(signatureEmpty){cout<<wittyComment();}
polylux
Posts: 267
Joined: Thu Aug 27, 2009 12:39 pm
Location: EU

Post by polylux »

The base line is:

Code: Select all

Object *name;
creates a pointer that's literally pointing to nowhere and - more importantly for you - DOES NOT create an object along with it.
What you can do now is let it point to (assign) an existing object or you create an object of type "Object" explicitly with the "new" operator:

Code: Select all

name = new Object();
Don't forget that you'll have to destroy (delete) dynamically allocated objects when you don't need them anymore:

Code: Select all

delete name;
Hope this helps a bit.

Cheers,
p.
beer->setMotivationCallback(this);
Post Reply