EventReceiver causes crash [Solved]
EventReceiver causes crash [Solved]
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
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!
-
- Posts: 63
- Joined: Thu Aug 05, 2004 9:40 am
- Location: Germany
I'm not too sure but I think it does..
CEventReceiver.h
Did I get it right?
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
Call me Wice, Miami Wice!
-
- Posts: 63
- Joined: Thu Aug 05, 2004 9:40 am
- Location: Germany
Backtrace how?
I've tried to comment out most but it still crashes. Remaining code:
CEventReceiver.cpp :CEventReceiver.h :
Thanks so far
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;
}
Code: Select all
#ifndef CEVENTRECEIVER_H
#define CEVENTRECEIVER_H
#include "irrHead.h"
class MyEventReceiver : public IEventReceiver
{
public:
virtual bool OnEvent(SEvent event);
};
#endif
Call me Wice, Miami Wice!
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...
Drop the virtual keyword and/or add a constructor.Code: Select all
class MyEventReceiver : public IEventReceiver { public: virtual bool OnEvent(SEvent event); void manageEvents(); };
If it does'nt work, I'm running out of ideas.
T.D.
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.
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.
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
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!
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.
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;
};