[fixed]Edit box still receiving events after removed (crash)

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
wasup999999
Posts: 3
Joined: Mon Mar 30, 2009 3:21 am
Contact:

[fixed]Edit box still receiving events after removed (crash)

Post by wasup999999 »

When an edit box is removed, I'd assume that the GUIEnvironment's focus is not set to NULL if the edit box that is removed has the current focus.


Simple code that will recreate the crash, all you have to do is select the edit box and hit enter twice:

Code: Select all


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

using namespace irr;

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

#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#endif

class MyEventReceiver : public IEventReceiver
{
public:
	MyEventReceiver(IGUIEnvironment* Env) : env(Env) { }

	virtual bool OnEvent(const SEvent& event)
	{
		if (event.EventType == EET_GUI_EVENT)
		{
			switch(event.GUIEvent.EventType)
			{
			case EGET_EDITBOX_ENTER:
                // On enter, remove the box
                printf("\n%p\n", event.GUIEvent.Caller);

                if (event.GUIEvent.Caller != NULL)
                    event.GUIEvent.Caller->remove();

				break;


			default:
				break;
			}
		}

		return false;
	}

private:
	IGUIEnvironment* env;
};


int main()
{

	IrrlichtDevice * device = createDevice(EDT_SOFTWARE, core::dimension2d<s32>(640, 480));

    printf("Select inside the edit box and hit enter, then hit enter again.");

	if (device == 0)
		return 1; // could not create selected driver.

	device->setWindowCaption(L"Hit enter twice in text box to crash");

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

    /// Initially add device
	env->addEditBox(L"Select and hit enter twice", rect<s32>(350, 80, 550, 100));

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

	while(device->run() && driver)
	if (device->isWindowActive())
	{
		driver->beginScene(true, true, SColor(0,200,200,200));

		env->drawAll();

		driver->endScene();
	}

	device->drop();

	return 0;
}


Output when done:

Code: Select all

Irrlicht Engine version 1.5
Microsoft Windows XP Personal Service Pack 3 (Build 2600)
Select inside the edit box and hit enter, then hit enter again.
009E9728

gdb reports:

Code: Select all

Program received signal SIGSEGV, Segmentation fault.
In irr::gui::CGUIEditBox::processKey () (C:\Program Files\CodeBlocks\MinGW\irrlicht-1.5\bin\Win32-gcc\Irrlicht.dll)
Being new here (and programming for the most part), I'm not sure what to do other than making this post (I read the rules but a bit went over my head). I didn't post on the tracker or anything since I don't wanna make a mistake etc.

PS: The fix probably needs to be sure to NOT call EGET_ELEMENT_FOCUS_LOST, could cause problems in programs if they happen to remove elements when focus is lost.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Got fixed, but you need svn version: http://irrlicht.sourceforge.net/phpBB2/ ... cus+remove
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply