EventReceiver causes crash [Solved]

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Saku
Posts: 158
Joined: Wed Jan 05, 2005 8:48 am
Location: Denmark

EventReceiver causes crash [Solved]

Post by Saku »

Hi,

As the title says my EventReceiver crashes my game. The game runs perfectly when I comment out:
" device->setEventReceiver(&receiver); "

My EventReceiver is placed in some cpp and h files besides the core.
The weird part is my game does not crash here but first when I use this line:
" ISceneNode* map = smgr->addOctTreeSceneNode(smgr->getMesh(file)); "

I even declare a couple of pointers in some lines between.

Anyone else have had the same problem or maybe just have a solution?? :?:

/Saku
Last edited by Saku on Fri May 27, 2005 4:59 pm, edited 1 time in total.
Call me Wice, Miami Wice!
Thulsa Doom
Posts: 63
Joined: Thu Aug 05, 2004 9:40 am
Location: Germany

Post by Thulsa Doom »

Your EventReceiver may implement an OnEvent() function but does not inherit from IEventReceiver(). After a mesh is successfully loaded, a message is passed to the EventReceiver and the exeption occurs.
Saku
Posts: 158
Joined: Wed Jan 05, 2005 8:48 am
Location: Denmark

Post by Saku »

I'm not too sure but I think it does..

CEventReceiver.h

Code: Select all

#ifndef CEVENTRECEIVER_H
#define CEVENTRECEIVER_H

#include "irrHead.h"

class MyEventReceiver : public IEventReceiver
{     
public:
	virtual bool OnEvent(SEvent event);
	void manageEvents();
};

#endif
Did I get it right?
Call me Wice, Miami Wice!
Thulsa Doom
Posts: 63
Joined: Thu Aug 05, 2004 9:40 am
Location: Germany

Post by Thulsa Doom »

The exception seems to occur ether in

virtual bool OnEvent(SEvent event);
or
void manageEvents();

try to backtrace it.
Saku
Posts: 158
Joined: Wed Jan 05, 2005 8:48 am
Location: Denmark

Post by Saku »

Backtrace how? :?
I've tried to comment out most but it still crashes. Remaining code:

CEventReceiver.cpp :

Code: Select all

#include "irrHead.h"
#include "CEventReceiver.h"

extern IrrlichtDevice* device;

bool MyEventReceiver::OnEvent(SEvent event)
{
	return true;
}
CEventReceiver.h :

Code: Select all

#ifndef CEVENTRECEIVER_H
#define CEVENTRECEIVER_H
#include "irrHead.h"

class MyEventReceiver : public IEventReceiver
{     
public:
	virtual bool OnEvent(SEvent event);
};
#endif 
Thanks so far :!: :D
Call me Wice, Miami Wice!
bal
Posts: 829
Joined: Fri Jun 18, 2004 5:19 pm
Location: Geluwe, Belgium

Post by bal »

I don't think this really matters but now you're constantly sending events, so ry changing "return true;" into "return false;". How do you declare the variable "receiver" ? Make sure it's declared as "MyEventReceiver receiver;" and not as a pointer, although, that should throw a compile-time error...
General Tools List
General FAQ
System: AMD Barton 2600+, 512MB, 9600XT 256MB, WinXP + FC3
Saku
Posts: 158
Joined: Wed Jan 05, 2005 8:48 am
Location: Denmark

Post by Saku »

In my case it doesn't matter. I've tried both and none works.
I double checked the declaration and I do exactly like you suggest.
Call me Wice, Miami Wice!
Guest

Post by Guest »

Code: Select all

class MyEventReceiver : public IEventReceiver
{     
public:
   virtual bool OnEvent(SEvent event);
   void manageEvents();
}; 
Drop the virtual keyword and/or add a constructor.
If it does'nt work, I'm running out of ideas.

T.D. :?
Guest

Post by Guest »

Neither of those two should make a difference - you don't need a constructor if you're not defining any extra fields, and virtual just means that the function can be overridden in derived classes.

But I'm surprised at how little information Saku is giving. Frankly I'm surprised bal and TD have been able to give as much advice as they did. Am I not seeing a link or something?

Anyway, post the relevant section of your main function. We should at least be able to look at any event receiver related stuff there - since the most likely cause of a crash is an invalid pointer.
Saku
Posts: 158
Joined: Wed Jan 05, 2005 8:48 am
Location: Denmark

Post by Saku »

You are so very right! None of them worked.
And if you want more of the code, just ask. I have no problem posting all my code here, but I thought ppl would just be annoyed by page on page of unrelevant code. I've packed all my code and uploaded here: http://www.zOneOne.dk/files/pack.zip

Also I'm very thankfull for ppl being willing to help me.
If you got any questions or anything just ask!

/Saku
Call me Wice, Miami Wice!
ondrew
Posts: 20
Joined: Fri Oct 03, 2003 2:24 pm
Location: Czech Republic

Post by ondrew »

easy stuff, the same happened to me.

you are declaring your variable "receiver" in CCore.cpp in InitDevice(), but it's only a local variable. So as soon as InitDevice() ends, your variable "receiver" is destroyed, memory freed ...

I would define your receiver as part of the CCore class.

Code: Select all

class CCore
{
public:
        void InitDevice();
        void InitGame();                                                                
        void Run();
        MyEventReceiver receiver;
};
Saku
Posts: 158
Joined: Wed Jan 05, 2005 8:48 am
Location: Denmark

Post by Saku »

:shock: ..it worked..
:oops: Did I mention I'm a noob ? :lol:

THANKS! Thank you Ondrew!
And thank you all for being pacient with me 8)

/Saku
Call me Wice, Miami Wice!
Post Reply