[no bug] Irrlicht 1.6 gcc -O2 flag disables GUI Events

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
Tobias
Posts: 3
Joined: Sun Nov 15, 2009 9:31 pm

[no bug] Irrlicht 1.6 gcc -O2 flag disables GUI Events

Post by Tobias »

Seems kind of wrong to post a bug as my first post, but I did not find anything about this problem when searching the forum and the tracker.

When I compile my very simple program (a small scene graph and a camera moving around it in a circle, two irrlicht buttons) and compile it with the -O2 flag the GUI-events do not show up in my event handler. I get events, just not any GUI related ones. If I compile without O or with O1, it works fine.

This might of course be a compiler issue rather than a Irrlicht issue, I am using gcc version 4.3.3 installed from synaptic on my Ubuntu 9.04 box. I am running a 64-bit machine and using hardware accelerated OpenGL.

Should I create a bug report for this?

Regards

-Tobias


EDIT: There is a ticket (2898660) for this now.
Last edited by Tobias on Mon Nov 16, 2009 8:09 pm, edited 1 time in total.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Create a simple program which can be used to reproduce this problem, describe the exact setting used, and post both here and on the bug tracker. But this can be indeed a problem with the compiler as well, we'll see.
Tobias
Posts: 3
Joined: Sun Nov 15, 2009 9:31 pm

Post by Tobias »

Code: Select all


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

using irr::s32;
using irr::u32;
using irr::createDevice;
using irr::core::vector3df;
using irr::core::rect;
using irr::core::dimension2d;
using irr::scene::ICameraSceneNode;
using irr::scene::ISceneManager;
using irr::scene::ISceneNode;
using irr::video::SColor;
using irr::video::EDT_OPENGL;
using irr::video::IVideoDriver;
using irr::gui::IGUIEnvironment;

/* BEGIN SOME COPY PASTE FROM IRR'S GUI TUTORIAL */

// Declare a structure to hold some context for the event receiver so that it
// has it available inside its OnEvent() method.
struct SAppContext
{
        irr::IrrlichtDevice *device;
        s32                             counter;
};

// Define some values that we'll use to identify individual GUI controls.
enum
{
        GUI_ID_ADVANCE_BUTTON = 101,
	GUI_ID_UPDATE_BUTTON
};

class MyEventReceiver : public irr::IEventReceiver
{
public:
    MyEventReceiver(SAppContext & context) : Context(context) {} 

    virtual bool OnEvent(const irr::SEvent& event)
    {
           if (event.EventType == irr::EET_GUI_EVENT)
           {
		s32 id = event.GUIEvent.Caller->getID();
                IGUIEnvironment* env = Context.device->getGUIEnvironment();

                switch(event.GUIEvent.EventType)
                {
		    case irr::gui::EGET_BUTTON_CLICKED:
			switch(id)
			{
			    case GUI_ID_ADVANCE_BUTTON:
				std::cout << "ADVANCE\n";
				    return true;
		            case GUI_ID_UPDATE_BUTTON:
			        std::cout << "UPDATE\n";
				return true;
			    default:
				return false;
			}
		    defalt:
			return false;
		}
	    }
    }
private:
    SAppContext &Context;	
};





/* END PASTE */




int main() {
    irr::IrrlichtDevice *device =
	createDevice(EDT_OPENGL, dimension2d<u32>(640, 480), 16,
		false, false, false, 0);
    if (!device)
	return 1;

    IVideoDriver* driver = device->getVideoDriver();
    ISceneManager* smgr = device->getSceneManager();
    IGUIEnvironment* guienv = device->getGUIEnvironment();
    guienv->addButton(rect<s32>(10,240,110,240 + 32), 0, GUI_ID_ADVANCE_BUTTON,
                        L"Advance", L"Advance the string");

    guienv->addButton(rect<s32>(10,280,110,280 + 32), 0, GUI_ID_UPDATE_BUTTON,
                        L"Update", L"Update the string for the turtle");

    
    // Store the appropriate data in a context structure.
        SAppContext context;
        context.device = device;
        context.counter = 0;

    MyEventReceiver receiver(context);
    device->setEventReceiver(&receiver);
    ICameraSceneNode *camera =
	smgr->addCameraSceneNode(0, vector3df(0,20,-40), vector3df(0,5,0));

    while(device->run())
    {
	camera->setPosition(vector3df(0,10,-20));
	driver->beginScene(true, true, SColor(255,0x00,0x00,0x00));
	smgr->drawAll();
	guienv->drawAll();
	driver->endScene();
    }

    device->drop();

    return 0;
}
Most of it is from the tutorial on GUIs

I compiled it with:

Code: Select all

g++ -O2 main.cpp -lIrrlicht -lGL -lXxf86vm -lXext -lX11
and GUI events did not show up

I compiled it with:

Code: Select all

g++ -O1 main.cpp -lIrrlicht -lGL -lXxf86vm -lXext -lX11
and they did show up
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Hint: compile always with -Wall and fix all warnings.
In this case you did not return any value for OnEvent in some cases which results in an "control reaches end of non-void function" warning. Which means that it's undefined and it seems the compiler uses different results in -o2 than with other settings (and he is allowed to do that!).

Fix it and your code works.
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
Tobias
Posts: 3
Joined: Sun Nov 15, 2009 9:31 pm

Post by Tobias »

Well, that's embarrassing, especially since I have seen the exact same kind of problem in other situations (the fall back return value differing with different optimizations) :oops:

I am really sorry for wasting your time, but thanks for the help.

One thing I wonder though, how can my bad return value from a non-gui-event prevent a gui-event from showing up? (please do not take this question as a challenge to your answer, just curiosity)
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Tobias wrote: One thing I wonder though, how can my bad return value from a non-gui-event prevent a gui-event from showing up? (please do not take this question as a challenge to your answer, just curiosity)
If OnEvent returns true it means that the event should no further be processed. So my guess would be that a mouse-click event (which you receive before the gui) was catched that way.
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