Fixed an important infinite loop bug in text drawing