Event receiver problem

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
unclejoe
Posts: 10
Joined: Fri Mar 28, 2008 2:27 pm
Location: Europe

Event receiver problem

Post by unclejoe »

hi fellas,
i'm working on some kind of a level editor for my game that i haven't made yet, to improve my skills, but there's a little problemo with my code.

i've created a menubar usin' the built-in gui functionality, but soon as i set an event receiver object for the device, the menus won't work anymore.

i've been searching for answers some time now, and i can't seem to figure it out. the event receiver is based on the one in that mesh viewer tutorial (n° 9) doesn't differs much from my code, but when i compile the tutorial, there is no problemos!!

anyone can see what i'm doin' wrong?


reward is 50,000 $...

here is the freakin' code:

Code: Select all

#include <irrlicht.h>
#include <iostream>

using namespace std;
using namespace irr;

#pragma comment(lib, "Irrlicht.lib")

IrrlichtDevice * device = 0;

class CEventReceiver : public IEventReceiver {
	public:
		virtual bool OnEvent (const SEvent &event) {
			switch (event.EventType) {
				case EET_KEY_INPUT_EVENT:
					switch (event.KeyInput.Key) {
						case KEY_ESCAPE:
							device->closeDevice ();
							break;
					}
					break;
				case EET_GUI_EVENT:
					gui::IGUIEnvironment * guienv = device->getGUIEnvironment ();
					switch (event.GUIEvent.EventType) {
						case gui::EGET_MENU_ITEM_SELECTED:
							gui::IGUIContextMenu * menu = (gui::IGUIContextMenu *)event.GUIEvent.Caller;
							s32 id = menu->getItemCommandId (menu->getSelectedItem () );
							switch (id) {
								case 100:
									//new...
									break;
								case 101:
									//open...
									break;
								case 102:
									//save
									break;
								case 103:
									//save as...
									break;
								case 104:
									//close
									break;
								case 105:
									//exit
									break;
								case 106:
									//view toolbar
									break;
								case 107:
									//view list of objects
									break;
								case 108:
									//view map
									break;
								case 109:
									//view settings
									break;
								case 110:
									//tip of the day
									break;
								case 111:
									//contents
									break;
								case 112:
									//visit website
									break;
								case 113:
									//about
									break;
							} // end switch (id)
							break;
					}
			}
		}
} receiver;

video::E_DRIVER_TYPE getDriverType () {
	c8 key;
	cout << "\n";
	cout << " 1 - Direct3D 9.0c\n";
	cout << " 2 - Direct3D 8.1\n";
	cout << " 3 - OpenGL 2\n";
	cout << " 4 - Software\n";
	cout << "Please pick a video driver of choise: ";
	
	cin >> key;
	
	switch (key) {
		case '1': return (video::EDT_DIRECT3D9);
		case '2': return (video::EDT_DIRECT3D8);
		case '3': return (video::EDT_OPENGL);
		case '4': return (video::EDT_BURNINGSVIDEO);
		default: return (getDriverType () );
	}
}

int main () {
	device = createDevice (getDriverType (), core::dimension2d<s32> (800, 480), 32, false, true,
									false, 0, IRRLICHT_SDK_VERSION);
	if (!device)
		return 1;
		
	device->setResizeAble (true);
	device->setEventReceiver (&receiver);
	
	video::IVideoDriver * driver = device->getVideoDriver ();
	gui::IGUIEnvironment * guienv = device->getGUIEnvironment ();
	scene::ISceneManager * smgr = device->getSceneManager ();
	gui::IGUIFont * font = guienv->getFont ("resources\\font.png");
	gui::IGUISkin * skin = guienv->getSkin ();
	
	skin->setFont (font);
	
	device->setWindowCaption (L"World Editor v1.0 - Untitled");
	
	
	gui::IGUIContextMenu * menu = guienv->addMenu (0, 100);
	menu->addItem (L"File", -1, true, true, false);
	menu->addItem (L"View", -1, true, true, false);
	menu->addItem (L"Help", -1, true, true, false);
	
	gui::IGUIContextMenu * submenu;
	submenu = menu->getSubMenu (0);
	submenu->addItem (L"New...", 100);
	submenu->addItem (L"Open...", 101);
	submenu->addItem (L"Save", 102);
	submenu->addItem (L"Save as...", 103);
	submenu->addItem (L"Close", 104);
	submenu->addItem (L"Exit", 105);
	
	submenu = menu->getSubMenu (1);
	submenu->addItem (L"Toolbar", 106);
	submenu->addItem (L"List of Objects", 107);
	submenu->addItem (L"Map", 108);
	submenu->addItem (L"Settings", 109);
	
	submenu = menu->getSubMenu (2);
	submenu->addItem (L"Tip of the day", 110);
	submenu->addItem (L"Contents", 111);
	submenu->addItem (L"Visit website", 112);
	submenu->addItem (L"About", 113);
	
	gui::IGUIStaticText * txtFPS = guienv->addStaticText (L"", core::rect<s32> (256, 2, 360, 18),
																					true, false, menu, 200, true);
		
	while (device->run () ) {
		core::stringw str = L"FPS: ";
		str += driver->getFPS ();
		txtFPS->setText (str.c_str () );
		driver->beginScene (true, true, video::SColor (255, 96, 96, 96) );
		
		smgr->drawAll ();
		guienv->drawAll ();
		
		driver->endScene ();
	}
	
	device->drop ();
	return 0;
}
the problemo must have something to do with the event receiver, cos when i disable this line:

Code: Select all

device->setEventReceiver (&receiver);
by putting those /* and */ thin's around it, the menus are doing their job!
but of course then the event receiver is disabled to!! this is freaking me out!

IDE is Dev-C++ 4.9.9.2 thing (windows version), usin' built-in compiler gcc,
i have the latest version of Irrlicht (1.4)[/code]
Last edited by unclejoe on Fri Mar 28, 2008 2:59 pm, edited 1 time in total.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

You don't return a value from OnEvent. You should return false, that will probably fix the problem.
Image Image Image
unclejoe
Posts: 10
Joined: Fri Mar 28, 2008 2:27 pm
Location: Europe

Post by unclejoe »

thank you so much!
you saved my day!
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Now give me my $50k or i'll tell rogerborg that you've been doing inappropriate things with alyson hannigan.... :twisted:
Image Image Image
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Unpossible; nothing would be inappropriate with that dirty minded minx.

I'm more interested in what sort of whacked out compiler would even compile a bool method that doesn't return a value. At the very least it should be shrieking a warning that it's returning garbage.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

i've fallen into this sort of trap before actually, using Visual C++... not sure if a warning's ever been put up but it certainly should have been!
Image Image Image
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

The VC8 (2005) cl.exe barfs a genuine error on that code, as it should.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
unclejoe
Posts: 10
Joined: Fri Mar 28, 2008 2:27 pm
Location: Europe

Post by unclejoe »

you're right, i'm not very happy with dev-c++, the software is quite buggy and there are alot of crashes. i have used visual studio 2008 for some time, but that installed to much crap on my system. maybe i should try code::blocks or get back to visual studio.

@JP: i'm sorry but i'm afraid the $50K was just a little joke.
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

unclejoe wrote:@JP: i'm sorry but i'm afraid the $50K was just a little joke.
LOL!! Of course he knows :lol:
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
Post Reply