I'll create a test case next week. Beforehand some information:
System Hardware: 4th Gen i7 Quad Core 3.2 GHz, 32GiB RAM, Intel HD + nvidia Hybrid
System OS: Gentoo Linux
Fonts tested: DejaVuSansMono-Bold.ttf, FreeMonoBold.ttf and FreeSansBold.ttf.
I first suspected that I have an error that accidentally writes over an array bound garbling the font or something like that. So I tried address sanitizer and leak sanitizer plus strong stack protection. Neither came up with anything.
To check whether the sanitizers didn't miss anything crucial I switched the fonts, so the one used for the width calculation is declared first. Currently the one for drawing is declared first. If anything corrupted any stack the display should be garbled again, but it isn't.
Then I added font reloading before each drawing block, and see, the display is fine when reloaded. But I can not reload the font for every frame. It was just a test.
The only possibility left is, that al_get_text_width() somehow corrupts the font memory, but only if the font is loaded into video memory.
If I put a al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP) just before the font loading, everything is fine and the FPS rate drops from a fixed 60 FPS to ~10 FPS.
See the mini screenshots for examples.
However, I just tried to run the game using primusrun/optirun (bumblebee, a system to use any program with the nvidia graphics card instead of intel HD) an noticed something strange.
I am describing it here, because it might be be caused by me missing some important step, that is somehow responsible for the missing glyphs as well. One might never know.
The screenshots are from the "Shopping screen" of the game, which can be seen before each round. Before entering here al_get_text_width() is nowhere used, so the missing glyphs show up here first.
Whenever the display is updated, it switches between the old screen (main menu of the game with loading / starting options) and the shopping screen. It is like al_flip_display() is flipping the displays backbuffer with an old state, too.
So I clear the backbuffer to a green color, draw the shop on it and it is shown. The next frame has the old screen with only the shop stuff drawn to it.
How can this be? Is there something special to be done when using nvidia cards?
Thanks for your help and patience!