Error setting event receiver

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
Boca
Posts: 12
Joined: Tue Mar 04, 2008 4:35 pm
Location: Spain

Error setting event receiver

Post by Boca »

My program is compiled but when I run it, it blocks. When I close this, Windows gives me the typical error window (send error or not send). Debuging, vc++ says: "Infraction of access on having read the location 0xccccccd0."

This is my init code:

Code: Select all

EventReceiver receiver; 
device->setEventReceiver(&receiver); 
...and this my event receiver class:

Code: Select all

int tecla = 0; 

class EventReceiver : public IEventReceiver
{
public:
	virtual bool OnEvent(const SEvent& event)
	{
		if(event.EventType == irr::EET_KEY_INPUT_EVENT)
		{
			if(!event.KeyInput.PressedDown)
			{
				tecla = event.KeyInput.Key;
				
			}
		}

		return false;
	}
};
If I quit "EventReceiver receiver;
device->setEventReceiver(&receiver);", there aren't errors. :roll: Heelp!!
CuteAlien
Admin
Posts: 9933
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

That's not enough information to help. Maybe you set receiver within some sub-function, so it's out of scope and no longer valid memory? Or maybe you do something once tecla is true which causes the problem?

But could also be other reasons which we can't see with that code. The eventreceiver looks ok and as long as the scope of receiver is fine you also set it the right way. So your problem is in another place.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
radiant
Posts: 112
Joined: Fri Feb 22, 2008 8:04 pm
Location: Mexico

Post by radiant »

You are not actually creating your event receiver, change this:

Code: Select all

EventReceiver receiver;
device->setEventReceiver(&receiver);
to this:

Code: Select all

EventReceiver receiver = EventReceiver();
device->setEventReceiver(&receiver);
That should sifice to make it work

Best regards
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

No, the two versions are exactly the same besides that one uses the default constructor while the other uses the copy constructor (IMHO). I suspect the same problem CuteAlien already mentioned.
radiant
Posts: 112
Joined: Fri Feb 22, 2008 8:04 pm
Location: Mexico

Post by radiant »

hehehe i was about to delete that post, i gues im still sleepy =P.
could u post the rest of the code, and one more thing, debug your app a little, put breakpoints in the onevent method and see what happends, check where do u get the null pointer(that error is usually due to a null pointer somewhere, thats why i sugested the constructor thing, when u dont initialize a var u get that error).

Best regards
Boca
Posts: 12
Joined: Tue Mar 04, 2008 4:35 pm
Location: Spain

Post by Boca »

:D I could solve the error!! I done a little change: I moved receiver declaration to namespace area (I done it global).

Thank you very much for your help!

The problem was that receiver was declared in a function, so, it was deleted when the function finish.
Post Reply