Page 1 of 1

dynamic_cast of IGUIElement seg faults

Posted: Sun May 24, 2015 6:01 am
by fargoth
It seems irrlicht is configured to compile with no RTTI - Is there a reason why I shouldn't enable it?

Maybe I should modify how I go about things?
I'm casting to get the gui values after a button was clicked, e.g:

Code: Select all

unsigned int CMazeGameMenu::getChosenNumOfAIPlayers()
    {
        float numOfAI = dynamic_cast<irr::gui::IGUISpinBox *>(
            _guiEnv->getRootGUIElement()->getElementFromId(MenuElement::MazeNumOfAI))->getValue();
        return static_cast<unsigned int>(round(numOfAI));
    }
Is there a better way, or should I just recompile the library with RTTI on?

Re: dynamic_cast of IGUIElement seg faults

Posted: Sun May 24, 2015 7:45 am
by hendu
RTTI brings 10% more binary size, and some runtime overhead as well.

Re: dynamic_cast of IGUIElement seg faults

Posted: Mon May 25, 2015 11:04 am
by CuteAlien
I never tried it with rtti. For reasons hendu mentioned it's usually not used in game industry (at least all engines I worked with so far had disabled it). You have to use comparisons with getType() instead. In this case for EGUIET_SPIN_BOX.

Re: dynamic_cast of IGUIElement seg faults

Posted: Wed May 27, 2015 5:29 pm
by fargoth
But to access the function of the spinbox from the base guielement pointer I still have to dynamic_cast, don't I?
My game crushed on me before I turned RTTI on, and the only thing I did was dynamic_cast, I didn't even use typeid...

Re: dynamic_cast of IGUIElement seg faults

Posted: Wed May 27, 2015 6:42 pm
by CuteAlien
No, you can use static_cast when you know the type will be fine.