Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stb_truetype: stbtt_GetCodepointHMetrics() outputs weird advanceWidth values after being called several times #1601

Open
Alihene opened this issue Jan 28, 2024 · 1 comment

Comments

@Alihene
Copy link

Alihene commented Jan 28, 2024

Describe the bug
When calling stbtt_GetCodepointHMetrics() on every character of a string, after a certain point the advanceWidth ends up being set to weird values. When using Arial, the advance width gets set to 13235 at a certain character and then 0 for the remaining characters. The point at which the values get weird varies for every string, The values are sometimes negative as well, for example -32548. however it mostly occurs in strings that are 30+ characters long. As a side note, no kerning is present.

To Reproduce

  1. Init "Arial" font
  2. Loop through every character in the string abcdefghijklmnopqrstuvwxyz1234567890 and call stbtt_GetCodepointHMetrics() on every character (the advanceWidth should become 13235 for the character 8)

Expected behavior
The advanceWidth should be the correct advance width for the character.

Screenshots
Screenshot_20240128_152223

@scippie75
Copy link

You should share your code.
Sounds like you maybe freed/released the ttf data itself and only kept the font_info struct? The ttf font data should also be kept in memory for as long as you use the font.

It's hard to detect that problem because right after doing it, the memory may no longer be 'allocated' according to the system but the data is still in there and is in a page you have been granted access to. When you start allocating new things, that space gets overwritten and starts invalidating the font data that is still being used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants