some point size + some strings = crash

Hi everybody,

I stumbled upon something that crashes Panda. The following code generates failed assertions and cause the crash. Further details and things to try are provided in the comments. Can somebody reproduce the problem? I’ve only tried on Panda 1.6.1

import direct.directbase.DirectStart
from pandac.PandaModules import TextNode, TransformState

font = loader.loadFont("/c/Windows/Fonts/arial.ttf")
font.setPointSize(71) ## a crash occurs when using the first string
#font.setPointSize(72) ## a crash occurs when using the second string
#font.setPointSize(73) ## neither strings cause a crash 
font.setSpaceAdvance(1.9) # only needed for pretty output

## --------------------------------------------------------------------
## The following two strings of text will work with some but not all 
## values of the font's point size. With some values both strings work, 
## with some values both strings cause a crash and with some values 
## one string works while the other cause a crash. The list of example 
## values provided is not exhaustive. Other values of the font's point
## size or different strings will work or cause crashes without an
## apparent criteria.

## The following string works with point sizes 72 and 73, 
## but causes a crash with point size 71.
aString = "A line of text that only illustrates a point but does "+\
          "not convey information."

## The following string works with point sizes 71 and 73, 
## but causes a crash with point size 72.
#aString = "A very long line of text. I mean, very, very, very, "+\
#          "very, very, very long."
## ---------------------------------------------------------------------------

textNode = TextNode("textNode")

textNodePath = aspect2d.attachNewNode(textNode)
textNodePath.setPos(-1.2, 0, 0)


Sounds like you ran into the same problem reported in this thread.

It’s a bug in Panda, but no one’s ever hit it before because no one’s tried to set their point size quite so large before. To avoid it, either don’t set your point size so large, or set your page size larger to compensate.

Do you really need that much precision in your font texture?


Yes, it does seem related to the same issue. Certainly the crash’s output is very similar.

Regarding the need to set the texture’s precision so large: well, yes and no. When the font is rasterized with such a high point size the characters are properly sharp if they are 1 inch tall and can be considered ok(ish) even if they are double that size. Admittedly these are very large sizes for characters on screen in normal circumstances. But suppose you are rendering an in-game newspaper: it will easily have the whole range of character sizes from 8pt all the way to 72pt. On top of that add people with special accessibility needs who require larger than usual characters and the whole range is shifting further up. So, yes, I think that at least point size 72 should be reliably supported.

I’ll try and play with the page size though and in the worst case scenario I’ll live with point size 60.

Note the difference between point size and pixels-per-unit. The former adds more precision to your letters and also makes the font bigger; the latter only adds more precision to your letters without affecting the visible size of the font.

Making the letters 7.2 times larger (72 instead of 10) will consume approximately 7.2 * 7.2 == 50 times more texture memory for your font. So, although it is true there is some value in having that much detail in your font, you should be careful that you understand the technical tradeoffs. Maybe you’re not worried about texture memory utilization, in which case, go for it.

The bug in question has already been fixed in the Panda source, but you’ll have to wait for the next release (or download the source and build it yourself).


David, thanks for your reply. I did come across setPixelsPerUnit but I didn’t give it enough attention. Possibly because it’s only mentioned (briefly) in the API but not in the manual section concerning fonts and text? Maybe that’s something I can help with. :wink:

Concerning memory usage, yes, I can understand that sharper fonts require more texture memory. In the thread “Crisp text for all!” I tried using the polygonal render mode, which should (?) take less (non-texture) RAM then a rasterized counterpart, but many fonts caused Panda/Python to crash (see example code included in the thread) and I eventually abandoned that route. Not to mention that to achieve results similar to the rasterized version of the same font anti-aliasing has to be enabled and I don’t know how much that would be an impact on the GPU when there are large amounts of text displayed.

Thanks for fixing the bug though. It’s good to know that’s out of the way. Allright, let’s get back to my code and see what I can do with this new knowledge! Thank you again!

Yeah, polygonal text isn’t suited for large pages of small text. It’s mainly useful for very large titles and some 3-D special effects. You end up creating a very large number of vertices if you set your point size or your pixels-per-unit very high, and that might be even more expensive than texture memory (vertices are large).

But then, I think your super-large texture text is mainly useful for very large titles as well; but you’re welcome to use it as you see fit, of course. :slight_smile: