[fixed]spinbox killing the stack

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
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

[fixed]spinbox killing the stack

Post by slavik262 »

I'm making a texture atlas builder that takes several images and builds them into one large image for use later as a texture atlas. The program is mostly done, with a few things left to do, but I keep running into this stupid problem:

When you click add image (after clicking File -> New to create a new atlas), a modal window comes up that contains a text box and button to browse for the new image file and a spinbox for scaling the image. I set the range of the scale factor spinbox from 1 to 0.1, and the step size to 0.1. The problem is, whenever I type into the spinbox or bring its value to 0.1 via the arrows, the program crashes with a stack overflow error. I have no idea why, and when I set the minimum value of the spinbox to anything else all the problems go away.

I'd really appreciate any insight into why this is happening. Thanks in advance.

Source can be downloaded here.

http://www.mediafire.com/?zj1mzzzgwtt
CuteAlien
Admin
Posts: 9810
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Please be a little bit more specific. I'm not going to browse through the sources of your whole project searching for a place where there might be a problem (you didn't even give the filename or function where the problem sits).

Please try to reduce your problem to a few reproducible lines. Preferably post the lines in the forum here.
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
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

Sorry. The function just creates a modal window with the browse button, text box, and spinbox. If you want to see how the event handler manages these controls, just look at EventReceiver.cpp

I'm not doing anything with the spinbox in the event receiver other than just calling GetValue() when the user clicks Ok on the dialog.

Code: Select all

void BuilderGUI::ShowAddImageDialog(void)
{
	u32 width = 320;
	u32 height = 150;
	addImgDlg = env->addWindow(rect<s32>(position2d<s32>(SCREEN_W / 2 - width / 2, SCREEN_H / 2 - height / 2), dimension2d<s32>(width, height)),
		true, L"Add an Image");
	imgFilenameBox = env->addEditBox(NULL, rect<s32>(position2d<s32>(10, 30), dimension2d<s32>(200, 22)), true, addImgDlg);
	imgFilenameBox->setTextAlignment(EGUIA_LOWERRIGHT, EGUIA_CENTER);
	env->addButton(rect<s32>(position2d<s32>(220, 30), dimension2d<s32>(95, 22)), addImgDlg, GUI_ID_ADD_DIALOG_BROWSE_FILE, L"Browse...", L"Browse for a file");
	env->addStaticText(L"Image scaling factor:", rect<s32>(position2d<s32>(10, 70), dimension2d<s32>(200, 22)), false, true, addImgDlg);
	imgScaleNUD = env->addSpinBox(NULL, rect<s32>(position2d<s32>(220, 70), dimension2d<s32>(95, 22)), true, addImgDlg);
	imgScaleNUD->setDecimalPlaces(2);
	imgScaleNUD->setStepSize(0.10f);
	imgScaleNUD->setValue(1.0f);
	imgScaleNUD->setRange(0.10f, 1.00f);
	env->addButton(rect<s32>(position2d<s32>(width / 2 - 95 - 10, 110), dimension2d<s32>(95, 22)), addImgDlg, GUI_ID_ADD_DIALOG_OK, L"OK");
	env->addButton(rect<s32>(position2d<s32>(width / 2 + 10, 110), dimension2d<s32>(95, 22)), addImgDlg, GUI_ID_ADD_DIALOG_CANCEL, L"Cancel");
}
I don't know what could be causing this. I have another spinbox control in the main window that works perfectly, and whenever I set the range to anything else everything works fine.
CuteAlien
Admin
Posts: 9810
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

OK, I can reproduce it. Nice bug - I'll look into it.
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
CuteAlien
Admin
Posts: 9810
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Thanks for reporting. It's fixed now in the 1.6 branch in svn and will probably make in the upcoming 1.6.1 release.

Until then - avoid setting the range to 0.1 - it was caused by a floating point rounding error which happens due to computer not being able to really represent 0.1

Or apply that patch which I added to Irrlicht:

Code: Select all

Index: source/Irrlicht/CGUISpinBox.cpp
===================================================================
--- source/Irrlicht/CGUISpinBox.cpp     (revision 2961)
+++ source/Irrlicht/CGUISpinBox.cpp     (working copy)
@@ -236,9 +236,9 @@
 void CGUISpinBox::verifyValueRange()
 {
        f32 val = getValue();
-       if ( val < RangeMin )
+       if ( val+core::ROUNDING_ERROR_f32 < RangeMin )
                val = RangeMin;
-       else if ( val > RangeMax )
+       else if ( val-core::ROUNDING_ERROR_f32 > RangeMax )
                val = RangeMax;
        else
                return;
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
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

I assumed it had something to do with floating point rounding errors. While I'm new to Irrlicht, I've been working in C++ for the last three years and have run into lots of floting point issues in the past. Thanks a lot for the help.
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

CuteAlien wrote:Or apply that patch which I added to Irrlicht:
I love you for posting !!! :D
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Post Reply