problem with 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
Efrint
Posts: 18
Joined: Sat Dec 10, 2005 6:04 pm

problem with event receiver

Post by Efrint »

Hello,

I´ve got a problem with my event receiver. If i use it, the whole programm crashes....what did I wrong?

here is my code:

Code: Select all

class EventReceiver : public IEventReceiver
	{
	public:
		virtual bool OnEvent (SEvent event)
		{
			if (!event.KeyInput.PressedDown)
			{
				switch (event.KeyInput.Key)
				{
				case KEY_KEY_A:
					{
						Key_A = true;
					}
					return true;
				}
			}
			else
			{
				Key_A = false;
				return false;
			}
			return false;
		}
		
	};
I get no compiler error, but it just doesn´t work. The bool Key_A is declared....

I hope, you can help me.

Regards Efrint
krama757
Posts: 451
Joined: Sun Nov 06, 2005 12:07 am

Post by krama757 »

You sure its not some problem in the rest of your application?
Efrint
Posts: 18
Joined: Sat Dec 10, 2005 6:04 pm

Post by Efrint »

yes, i´m shure. If i use the application without this event receiver, everything works fine.
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

1) your code calls for every type of event, not just keyboard events. you need to check this
2) you have a "!" in your if statement. you know what this means right?
3) 'bool keys' is the snippet you need http://www.irrforge.org/index.php/Keybo ... keys.5B.5D
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
jam
Posts: 409
Joined: Fri Nov 04, 2005 3:52 am

Post by jam »

I tested your event reciever and I can not reproduce a crash, It works just fine here at least the way it's coded.
Efrint
Posts: 18
Joined: Sat Dec 10, 2005 6:04 pm

Post by Efrint »

@bitplane yes I know what a "!" means...

@jam but why does it crash on my computer...I´ve got Visual studio 6, is that the problem?

I create my device like that:

Code: Select all

device = createDevice(EDT_DIRECTX9,dimension2d<s32>(x,y),32, true, true, true, &receiver);
Efrint
Posts: 18
Joined: Sat Dec 10, 2005 6:04 pm

Post by Efrint »

*bump*

does nobody know the solution? :cry:
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

okay this calls for another guess- from the code you've posted so far, you're attaching the wrong event handler to your device.
device = createDevice(EDT_DIRECTX9,dimension2d<s32>(x,y),32, true, true, true, &EventReceiver);
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
Guest

Post by Guest »

why? i n the line above the create device, i wrote:

Code: Select all

EventReceiver receiver;
		if (DirectX == true)
		{
			device = createDevice(EDT_DIRECTX9,dimension2d<s32>(x,y),32, true, true, true, &receiver);
		}
[/quote]
Efrint
Posts: 18
Joined: Sat Dec 10, 2005 6:04 pm

Post by Efrint »

ohh....i wasn´t logged in....but as i said in my post (as a guest)...
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

oops yea sorry my bad. still have no idea. try putting some printf's in to your event reciever to track down where the crash occurs
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
Efrint
Posts: 18
Joined: Sat Dec 10, 2005 6:04 pm

Post by Efrint »

i tried to comment parts of my eventreceiver with "//" out. But even, if the event receiver does nothing, everything crashes.

EDIT: The last line that is written in the consol is: Loaded Texture: #DefaultFont

EDIT#2: If I debug that, i get the message, that there is an untreated exception, an access violation....in this line....

1007E511 call dword ptr [edi+4]
Efrint
Posts: 18
Joined: Sat Dec 10, 2005 6:04 pm

Post by Efrint »

*bump*

EDIT: Even if i use the event receiver from the movement tutorial, i get the same error?! There must be an error in the rest of my code.
Efrint
Posts: 18
Joined: Sat Dec 10, 2005 6:04 pm

Post by Efrint »

I found my error. It was so easy.....I declared my event receiver local in a function. Thank you all for your help :D
Post Reply