#16 FP DIV-by-zero when max GL texture size is small


I've run into a case where I am using FTGL on a platform where the max texture size is 512x512. When rendering a font glyph at size = 200 (which I then down-sample to 100 post-rendering), I encountered a crash near line #185 in src/FTFont/FTTextureFont.cpp. It appears that the glyphWidth parameter went higher (731) than the textureWidth parameter (512, due to HW restrictions). This causes the variable "h" to become zero, causing divide-by-zero when calculating textureHeight.

I noticed the mysterious "+ 0.5" on the end... is this an attempt to force rounding upward? If so, most compilers that I use seem to truncate this instead of rounding when performing a cast-to-int. On a hunch, I changed the cast into a call to the C99 lrintf() function (in math.h) and it seems to fix the problem for me.

I am attaching a patch below.


  • coleman kane

    coleman kane - 2009-03-18
    • priority: 5 --> 7
  • Sam Hocevar

    Sam Hocevar - 2010-05-22

    Thanks for reporting this. Your patch mitigates the issue but will still cause crashes at glyph sizes twice larger. A complete fix was applied in trunk.

  • Sam Hocevar

    Sam Hocevar - 2010-05-22
    • assigned_to: nobody --> sammy
    • status: open --> closed-fixed

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks