Page 1 of 1

[solved] Freeze-Crash Resizing a Button to a Point

Posted: Thu Aug 26, 2010 15:49
by crodgers
Hi CrazyEddie!

Let me start by saying that I really like the CEGUI project. I have used it for projects at work for 3+ years, mostly for the BBN VESSEL Damage Control Simulator, which won a couple awards over the past year: http://www.bbn.com/technology/immersive_learning_technologies/vessel

We have been working with CEGUI 0.6.x (with OpenGL rendering) for that project. In the game, several controls animate their size and position to help direct the players' eyes to important information and interface. All had been working fine until we ported over to CEGUI 0.7 when we encountered a strange freeze-crash that happened when scaling any button (with text) down to a point.

It turns out that the freeze was an infinite while-loop in RenderedStringWordWrapper::format. It would eventually crash because of the infinitely growing vector of lines, "d_lines".

Code: Select all

void RenderedStringWordWrapper<T>::format(const Size& area_size)
{
    deleteFormatters();

    RenderedString rstring, lstring;
    rstring = *d_renderedString;
    float rs_width;

    T* frs;

    for (size_t line = 0; line < rstring.getLineCount(); ++line)
    {
        while ((rs_width = rstring.getPixelSize(line).d_width) > 0)
        {
            // skip line if no wrapping occurs
            if (rs_width <= area_size.d_width)
                break;

            // split rstring at width into lstring and remaining rstring
            rstring.split(line, area_size.d_width, lstring);
            frs = new T(*new RenderedString(lstring));
            frs->format(area_size);
            d_lines.push_back(frs);
            line = 0;
        }
    }

    // last line.
    frs = new T(*new RenderedString(rstring));
    frs->format(area_size);
    d_lines.push_back(frs);
}

The break statement in the loop was never hit. At the point I was debugging, it was trying to split a single component (16 pixels wide) while the text area was pinched down to nearly a point (10 pixels wide).

For lack of other methods on RenderedString, I added this slightly hackish snip of code (as a fail-safe) right after the call to split:

Code: Select all

            if(rstring.getComponentCount() == 1 && rstring.getLineCount() == 1 && rs_width >= area_size.d_width)
               break;

I could have added a canSplit method to RenderedString, in order to simplify the if-statment, though I wanted to keep modifications to CEGUI to a minimum.

Hopefully this fix or something similar can make it into the next version of CEGUI. By the way, looking forward to the animation support in 0.7.2 :)

Thanks a bunch for your awesome work CrazyEddie!

Cheers,

Chris

Re: Freeze-Crash Resizing a Button to a Point

Posted: Fri Aug 27, 2010 05:45
by Timo
I'm 95% sure this has been fixed in the SVN version and latest snapshots.

Oh Eddie, you should release 0.7.2 already. :D

edit: ok, I see it's coming soon...

Re: Freeze-Crash Resizing a Button to a Point

Posted: Fri Aug 27, 2010 13:48
by crodgers
Thanks Timo :)

Looking forward to upgrading once the official release is available.

Cheers!