Details
-
Bug
-
Resolution: Done
-
P1: Critical
-
5.12.4
-
None
-
-
46d72a117df642135718b38995346267312c4808, 9a53834f1e7fce2fc3b1ecc2a311faedbc371d37
Description
There is a logical bug in the distance field cache that spans multiple textures. The way the glyphs are allocated in the cache, it creates a big area allocator with textureSize*textureCount height, and then allocates to this. But since the (glyph heights + padding + margin) are not necessarily a factor in the texture height, some of them may end up at the edge between two textures. The result of this is that the actual texture height will be larger than the maximum size, since it will be correctly expanded to account for the remaining part of the glyph that falls outside the texture.
In addition, the next texture will have an unused section to account for the overlap from the previous texture, but this is just a little wasteful, it is not a critical bug.
Since the case where the caches actually exceed a single maximum sized texture is so rare, we haven't actually seen this happen in the wild. But when using the distancefieldgenerator, it is quite easy to get into this situation since the default texture size is so low.
A proper fix for this would be to have a separate area allocator for each texture instead of one big one, but this would have some implications for the pregenerated cache format. We would still have to support the old in order to support older files.
So a quicker fix is to set the maximum height of the textures in the allocator to be maxSize - fontPixelSize. That way we leave space for exceeding the cache by up to one glyph height. It would be good enough for a rare case.