Closed AlbertoGP closed 3 years ago
I understand the problem but I can't understand why the FT_errors table is wrong. Do you know what is the reason ? We can of course use the second method if it fixes the problem. Can you make a PR?
Yes, I’ll make a PR soon. I also don’t know why the table is wrong if the implementation is exactly the one proposed by FreeType. I can only guess that it did work fine at the time when they wrote the documentation, maybe the error codes were all consecutive and later they removed some of them, which made the index no longer match the error code.
This problem seems to be a misunderstanding: FreeType’s documentation proposes this error array as one option but it does not say anywhere that the array should be indexed by error code. I guess they expected it to be accessed from a function that would scan it until finding the matching error code: otherwise there is no reason to have the error code in each entry.
I’m preparing the correction.
With the changes in this pull request, running markup
under the conditions for #210 shows me the correct error message:
Using GLEW 2.2.0
FT_Error (line 95, code 0x97) : invalid ppem value
Unable to load "/usr/share/fonts/TTF/DejaVuSans.ttf" (size=20.5)
FT_Error (line 95, code 0x97) : invalid ppem value
Unable to load "/usr/share/fonts/TTF/DejaVuSans.ttf" (size=20.5)
FT_Error (line 95, code 0x97) : invalid ppem value
Unable to load "/usr/share/fonts/TTF/DejaVuSans.ttf" (size=20.5)
FT_Error (line 95, code 0x97) : invalid ppem value
Unable to load "/usr/share/fonts/TTF/DejaVuSans.ttf" (size=20.5)
FT_Error (line 95, code 0x97) : invalid ppem value
Unable to load "/usr/share/fonts/TTF/DejaVuSans.ttf" (size=20.5)
FT_Error (line 95, code 0x97) : invalid ppem value
Unable to load "/usr/share/fonts/TTF/DejaVuSans-Bold.ttf" (size=20.5)
FT_Error (line 95, code 0x97) : invalid ppem value
Unable to load "/usr/share/fonts/TTF/DejaVuSans-Oblique.ttf" (size=20.5)
FT_Error (line 95, code 0x97) : invalid ppem value
Unable to load "/usr/share/fonts/TTF/DejaVuSans.ttf" (size=20.5)
Houston, we've got a problem !
Houston, we've got a problem !
Houston, we've got a problem !
Houston, we've got a problem !
Houston, we've got a problem !
Houston, we've got a problem !
Houston, we've got a problem !
Houston, we've got a problem !
Thanks, PR has been merged.
Hi, I’m debugging #210 and found that, at least in my system, the
FT_Errors[]
table (intexture-font.c
) does not work as intended.The error code returned by FT should work as an index in that table, but the error codes do not match their indexes. That causes incorrect error reports, for instance in #210 mentioned above, even if building such a table is one of the two methods recommended in the documentation for FreeType: https://www.freetype.org/freetype2/docs/reference/ft2-error_enumerations.html
In that case,
FT_Set_Char_Size()
(intexture_font_load_face()
) returns the error code0x97
(151 decimal) which corresponds to “invalid ppem value” [1] as you can see in https://www.freetype.org/freetype2/docs/reference/ft2-error_code_values.html[1] Those codes can change between releases, but this one matches as I show below. The error message “invalid ppem value” makes sense because the missing text appears if I round down the size parameter passed to
FT_Set_Char_Size()
.However, the code that handles the error code from
FT_Set_Char_Size()
at https://github.com/rougier/freetype-gl/blob/1559dcb8480bedad106fa4113a3102b83140b9f2/texture-font.c#L88 prints the wrong error message: FT_Error (line 89, code 0xf23045c8) : GL_ARB_draw_instancedThat is the result of a buffer overread because the error table has only 92 entries, so position 151 is outside of it. As a consequence, the error code changes each time I run the
markup
demo. The curious error string does stay constant, though.To verify the issue, I wrote a function that dumps the
FT_Errors[]
table:The result is the following:
I think the solution would be to use the other method, the
switch()
block, inside a function that returns the error string: https://www.freetype.org/freetype2/docs/reference/ft2-error_enumerations.html