Need help with a problem concerning IEventReceiver

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
Peter Müller
Posts: 292
Joined: Sun Mar 14, 2004 5:28 pm
Location: Germany
Contact:

Need help with a problem concerning IEventReceiver

Post by Peter Müller »

Hi there!
I've got a problem concerning the IEventReceiver

Here's a bit of my code

Code: Select all

// In "EventReceiver.h"
class CEventReceiver : public IEventReceiver
{
 public:

 void test(void)
 {
  printf("This text is shown\n");
 };

 virtual bool OnEvent(SEvent event)
 {
  printf("This text not :(\n");
  return false;
 };
};

Code: Select all

// In "Game.cpp"
void CGame::init_grafic(EDriverType edtDriverType)
{
 printf("Start:\n");
 this->svGameVar = (SGameVar*)malloc(sizeof(SGameVar));
 printf("1\n");
 this->svGameVar->receiver = (CEventReceiver*)malloc(sizeof(CEventReceiver));
 printf("2\n");
 this->svGameVar->receiver->test();
 printf("2.1\n");
 this->svGameVar->device = createDevice(edtDriverType, dimension2d<s32>(300,300), 32, false, false, this->svGameVar->receiver);
 printf("3\n");
 this->svGameVar->driver = this->svGameVar->device->getVideoDriver();
 printf("4\n");
 this->svGameVar->env = this->svGameVar->device->getGUIEnvironment();
 printf("5\n");
 this->svGameVar->smgr = this->svGameVar->device->getSceneManager();
 printf("6\n");
};

This is shown in the console:

Code: Select all

Start:
1
2
This text is shown
2.1
And then an error message with 0x1005afc0 and 0xcdcdcdcd




If I take

Code: Select all

this->svSpielVar->device = createDevice(edtDriverType, dimension2d<s32>(300,300), 32, false, false);
instead of

Code: Select all

this->svSpielVar->device = createDevice(edtDriverType, dimension2d<s32>(300,300), 32, false, false, this->svGameVar->receiver);
all works :?




I really hope, someone can help me, please :( :( :(
http://www.games-forge.de - Die Community für Nachwuchsprogrammierer
Peter Müller
Posts: 292
Joined: Sun Mar 14, 2004 5:28 pm
Location: Germany
Contact:

Post by Peter Müller »

somebody?
http://www.games-forge.de - Die Community für Nachwuchsprogrammierer
rincewind
Posts: 35
Joined: Thu Mar 25, 2004 5:28 pm
Location: Germany --> Bonn

Post by rincewind »

Hm, i'm not shure, but why don't you create your eventreceiver with new?
like

Code: Select all

this->svGameVar->receiver = new CEventReceiver();
greetings, rincewind
schick
Posts: 230
Joined: Tue Oct 07, 2003 3:55 pm
Location: Germany
Contact:

Post by schick »

First use a debugger :-), 2nd use a debugger.

If you write c++ applications, please do use new instead of malloc. The error messages are SEGFAULTS.

Try to create the eventreceiver using new. If it does not work try to make it static. But in fact if you would use a debugger there should be no problem to find out more information about the bug and finally get it fixed.
Please send me an e-mail instead of a private message.
Peter Müller
Posts: 292
Joined: Sun Mar 14, 2004 5:28 pm
Location: Germany
Contact:

Post by Peter Müller »

Thanks!
I'll trie it.

But I used a debugger. He showed me ASM Source, so I couldn't lokate the problem.

He only said this->SGameVar->receiver "Kann Ausdruck nicht auswerten" (in English: Expression cannot evaluate)
http://www.games-forge.de - Die Community für Nachwuchsprogrammierer
Peter Müller
Posts: 292
Joined: Sun Mar 14, 2004 5:28 pm
Location: Germany
Contact:

Post by Peter Müller »

Yahoo! Now it works. And I also know why!
When using malloc, I have to call the constructor manuell.
http://www.games-forge.de - Die Community für Nachwuchsprogrammierer
Dragon7
Posts: 7
Joined: Sun Apr 11, 2004 1:28 pm

Post by Dragon7 »

Yes, also, get more into C++ a bit and get rid of hungarian notation ;o
Post Reply