Strange bug with GUI and floating point values

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
Akabane87
Posts: 50
Joined: Sat May 05, 2012 6:11 pm

Strange bug with GUI and floating point values

Post by Akabane87 »

Hi there,

First of all I'm using a french version of windows and what follows is probably partially linked to this because it seems to be a float value replacement of the '.' letter with a "," (lots of software like excel do this replacement). The problem occurs with both 1.7.3 and 1.8 versions of irrlicht.

My problem is that when I perform an operation in my programm that implies the opening of an open dialog box, all my gui elements try to transform their '.' with ','. The problem is that spinboxes use the text value to increment or decrement the value when pressing up or down button and if the displayed value has a ',' instad of a '.' the float value is truncated and causes the decrement operation going bad (exiting the range value for exemple) and simply making the spin box malfunction.

I tried to reproduce this bug outside my project but I can't find what cause this.
In another hand I tried to debug what transform my '.' into ',' but I'm stuck because I have no symboles for irrlicht.dll. The only things I can tell by tracking the modification of the string value of my spinbox is that this change occurs (after doing my reproduction steps into my code) each time I press the down or up button of my spinbox. And since this is the only break I suppose that this correspond to the code that update the value with the step given to the spin box.

With this assumption I also tried to test all the code that update the value with the step to try to find which part of the code could have change my '.' but I haven't been able to find anything : the code works fine to convert the string into float and then test the ranges... And here I am completely lost with this bug.

What I can do is providing you a dump of my soft with the stack corresponding to the change of a correct string value (with a '.') by a bad value (with a ',') just after pressing the up button of my spin box. The stack only contains elements from the engine and none from my code so you shouldn't have to check my code.
I'm sorry to not being able to give you a correct reproduction of the bug.


edit : additionnal test done by me after the triggering of the bug

Code: Select all

                    m_DialogSpeedSpinBox->getEditBox()->setText(L"1.00000");// the bug is triggered and the value if fucked "1,10000" : I reset it manually with a correct value and write manually the content of an increment by the step value
 
                    f32 val = m_DialogSpeedSpinBox->getValue();// I get the previous value that is correct here (1.00000)
                    val += 0.1f;
                    wchar_t str[100];
                    core::stringw FormatString = "%.";
                    FormatString += 5;
                    FormatString += "f";
 
                    // content of setValue()
                    swprintf(str, 99, FormatString.c_str(), val);
                    m_DialogSpeedSpinBox->getEditBox()->setText(str);
 
                    // call of verifyValueRange();
                    val = m_DialogSpeedSpinBox->getValue();
                    if ( val+core::ROUNDING_ERROR_f32 < m_DialogSpeedSpinBox->getMin() )
                        val = m_DialogSpeedSpinBox->getMin();
                    else if ( val-core::ROUNDING_ERROR_f32 > m_DialogSpeedSpinBox->getMax() )
                        val = m_DialogSpeedSpinBox->getMax();
                    // all is ok here with this code : the value is 1.10000
 
                    // But if I call the original setValue here with my previous float value 1.10000, the value get fucked
                    //m_DialogSpeedSpinBox->setValue(val);
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Strange bug with GUI and floating point values

Post by CuteAlien »

Thanks, I've got a pretty good idea what's going on (setValue is using swprintf which cares about locales and getValue is is using fast_atof which doesn't). But will have to create a testcase for me and figure out first if we can avoid the trouble here somehow.

As workaround try adding the following to your application (needs Irrlicht 1.8):

Code: Select all

 
irr::core::LOCALE_DECIMAL_POINTS = irr::core::stringc(".,");
 
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
Akabane87
Posts: 50
Joined: Sat May 05, 2012 6:11 pm

Re: Strange bug with GUI and floating point values

Post by Akabane87 »

Thanks a lot this makes the spin boxes work with ','. But I'm still wondering why the , change doesn't happen when I write manually

Code: Select all

// content of setValue()
                    swprintf(str, 99, FormatString.c_str(), val);
                    m_DialogSpeedSpinBox->getEditBox()->setText(str);
from my code above.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Strange bug with GUI and floating point values

Post by CuteAlien »

Yeah, that's strange.
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
Akabane87
Posts: 50
Joined: Sat May 05, 2012 6:11 pm

Re: Strange bug with GUI and floating point values

Post by Akabane87 »

Maybe its linked to the fact that we call swprintf(str, 99, FormatString.c_str(), val); through the dll ?
If you want the dump file with the stack where the setValue fucked is called just tell me.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Strange bug with GUI and floating point values

Post by CuteAlien »

Thanks. But I think it'll take a while until I get to this (busy with not directly Irrlicht related stuff at the moment (stuff that might or might not become related at a later time) and a bunch of other open todo's already waiting on my Irrlicht list ...).
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