runtime Error related to GUI

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
Gav
Posts: 23
Joined: Fri Jul 16, 2004 12:28 pm

runtime Error related to GUI

Post by Gav »

hey people, just been messing with irrlicht to get to know the basics etc...

Im having some trouble with the following program - basically when i run it and click the "new window" button, it freezes and the windows error report message comes up (the graphical window closes, but the console window doesnt (comes up with "press any key" that you get at the end of a standard console app))

...I didnt really know what i could search for to answer this problem so sorry if its been asked already..

Code: Select all

#include <irrlicht.h>

using namespace irr;

using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

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

IrrlichtDevice* device = 0;
s32 counter = 0;
IGUIListBox* listBox = 0;

class MyEventReceiver : public IEventReceiver
{
public:
		virtual bool OnEvent (SEvent event)
		{
			if(event.EventType == EET_GUI_EVENT)
			{
				s32 id = event.GUIEvent.Caller->getID();
				gui::IGUIEnvironment* GUIEnv = device->getGUIEnvironment();

				switch(event.GUIEvent.EventType)
				{
					case EGET_BUTTON_CLICKED:
					{
						if(id == 101)
						{
							listBox->addItem(L"Window Created");
							counter+=30;
						
							if(counter > 200)
								counter = 0;
	
							IGUIWindow* window = GUIEnv->addWindow(rect<s32>(100+counter,
								                                        100+counter, 300+counter,
															            200+counter), false, L"Test");
	
							GUIEnv->addStaticText(L"Close me", rect<s32>(35,35,140,50),
								                                  true, false, window);

						}
						break;
					}
					default:
						break;

				}
				return true;
			}

			return false;
		}
};

int main()
{
	device = createDevice(video::EDT_DIRECTX8, core::dimension2d<s32>(640,480));

	if(device==0)
		return 1;

	MyEventReceiver receiver;
	device->setEventReceiver(&receiver);

	device->setWindowCaption(L"This will eventually be a calcluator");

	video::IVideoDriver* driver = device->getVideoDriver();
	IGUIEnvironment* env = device->getGUIEnvironment();

	env->addButton(rect<s32>(10,250,100,290), 0, 101, L"New Window");

	while(device->run() && driver)
	if(device->isWindowActive())
	{
		driver->beginScene(true, true, SColor(0, 0, 0, 255));
		env->drawAll();
		driver->endScene();
	}

	device->drop();

	return 0;
}


:? [/code]
warpd21
Posts: 1
Joined: Sat May 21, 2005 7:26 am

Trying to add an item to a listbox...

Post by warpd21 »

Remove these lines (bolded):

IrrlichtDevice* device = 0;
s32 counter = 0;
IGUIListBox* listBox = 0;
class MyEventReceiver : public IEventReceiver

......

switch(event.GUIEvent.EventType)
{
case EGET_BUTTON_CLICKED:
{
if(id == 101)
{
listBox->addItem(L"Window Created");
don_Pedro
Posts: 84
Joined: Fri Jun 10, 2005 1:34 pm
Location: Poland
Contact:

Post by don_Pedro »

You should actually create listBox, at the moment you have only null pointer. Insert

Code: Select all

listBox = env->addListBox(...)
with proper parameters, as you did with button.
Post Reply