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.
[no bug] Irrlicht 1.6 gcc -O2 flag disables GUI Events
[no bug] Irrlicht 1.6 gcc -O2 flag disables GUI Events
Last edited by Tobias on Mon Nov 16, 2009 8:09 pm, edited 1 time in total.
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;
}
I compiled it with:
Code: Select all
g++ -O2 main.cpp -lIrrlicht -lGL -lXxf86vm -lXext -lX11
I compiled it with:
Code: Select all
g++ -O1 main.cpp -lIrrlicht -lGL -lXxf86vm -lXext -lX11
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.
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
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)
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)
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)
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.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)
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm