bug in TextAreaOverlayElement

Minor issues with the Ogre API that can be trivial to fix
Post Reply
User avatar
lunkhound
Gremlin
Posts: 169
Joined: Sun Apr 29, 2012 1:03 am
Location: Santa Monica, California
x 19

bug in TextAreaOverlayElement

Post by lunkhound »

I'm new here, I've only been using Ogre for a couple of months and this is my first post. I'm not sure if this counts as a "papercut" or not.
I noticed that the FPS meter in my app (using a TextAreaOverlayElement) had a weird problem where the space character was displayed about twice as wide as it should be (I'm using a fixed-width font).
The strange thing is that this extra-wide space only seemed to affect that one TextAreaOverlayElement, other TextAreaOverlayElements that I created later had normal looking spaces. After a bit of debugging I think I found the issue, and it seems that if you create and use a TextAreaOverlayElement before the font has been loaded, it gets a bad value set in the mSpaceWidth member. I'm not setting the space-width at all. I made a local change in OgreTextAreaOverlayElement.cpp which appears to fix the issue:

OgreTextAreaOverlayElement.cpp, line 153:

Code: Select all

void TextAreaOverlayElement::updatePositionGeometry()
{
    float *pVert;

    if (mFont.isNull() || ! mFont->isLoaded())
    {
        // if font is not loaded, avoid setting mSpaceWidth with bad value
        // not initialised yet, probably due to the order of creation in a template
        return;
    }
    ...
Basically I just added the "font is loaded" check to this early-exit which prevents this function from using a bad value to initialize mSpaceWidth. I don't really know the code well enough to know if this is the right way to do it.
Post Reply