Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Some characters randomly missing when drawing text

This thread is locked; no one can reply to it. rss feed Print
Some characters randomly missing when drawing text
APrince
Member #12,698
March 2011

Hi, I used Allegro 5.0.6 and had a problem with the drawing text. Some part of the text is randomly missing. I upgraded to 5.0.8 but with no luck.

When I say "randomly" I mean this: I compile the program. Now when I launch it, some characters of the text are missing (although there is a gap just big enough to exactly hold the letter). When I close it and launch again, the exactly same character at exactly the same positions will be missing. If I however make a minor change to the source code (that is not connected to drawing the text at all. i.e. writing a command that has no impact on the program...) and compile again. Than some other characters will be missing.

I don't have a clue of what's this about because it seems so random. I also noticed that it seems to be related with the text aligned to the center and thus to calling al_get_text_width. Well I checked the result of this function and it always seems to return the correct width, the only problem is that the consequential text drawing (like x - text_width/2) will fail to print some letters, although their positions are correct. If I replace all the al_get_text_width calls the constants they return it seems* to work fine.

When I say that some letters are missing, I mean i.e. "S VE" instead of "SAVE", or " M88 " instead of "SDM88XX" and so on.

*Now I really don't know but I haven't found a single error. It may be a coincidence though.

Can you please tell me, what may be wrong?

Thanks

//edit: I have also noticed, that when one character misses, all the same characters will be missing as well. For example if 'f' is missing somewhere in the printed text, then the printed text will contain no 'f' at all. E.G. "font fails to print off" will become " ont ails to print o ". (in the printed text there will be a gap of exactly the same width as 'f' has on every place that 'f' occurs, as if the drawing function just didn't like the character and just didn't draw it, even though it moves the correctly calculates the position of the next letter even though it didn't render the previous one.).

torhu
Member #2,727
September 2002
avatar

Could be memory corruption. Try commenting out all the code that's not needed for testing your text printing code, and see if it works then.

APrince
Member #12,698
March 2011

Yes, it definitely has to be some memory corruption. Like I somehow overwrite the font somewhere. But how come, there is always the gap and not some trash? Is there some consistency check for that? Anyway I will probably try allegro debug build and see is there is any interesting log.

Some new info: I have found out that launching the application from outside the Visual Studio makes it to dislike different letters at different start ups. So even the same build behaves differently at every execution.

//edit: I have added an attachment (the log). If anyone can look at it, I would really appreciate it... It says something about FAKE FORMAT (near the end of the log), but I can't really read the log.

Kris Asick
Member #1,424
July 2001

My guess is that you're attempting to access an array out of bounds near your font object in memory, and thus changing things inside the font object.

That's just a guess though. Try drawing some text immediately after loading the font and see if it shows the same problem. If not, then something you're doing between loading the font and drawing text on-screen is accessing memory it shouldn't be.

As for the differences between running debug from Visual Studio and the binary itself, that's just a matter of where things end up in memory. Either way, something's up. :P

--- Kris Asick (Gemini)
--- http://www.pixelships.com

APrince
Member #12,698
March 2011

OK, I have spend lot of time (that I should actually devote to the Christmas clean up and other stuff :-) ) tracking the problem and I found out that it is caused by calling the

al_resize_display(display, display_width, display_height); //In my case 1030x743

function. By "caused" I mean that if I do not call this method, no characters will be missing. Now I don't really think there is any bug in my program, but who knows?

Now the strange thing is that if I use the character that disappears before calling the al_resize_display it will NOT disappear. If I use that font but not the character it will still disappear after calling al_resize_display and thus all the subsequent printed text with that particular font will result in an empty space on a place that the character should be. Is it possible that there is any problem in al_resize_display?

In my case, I have two fonts and in one of them character 'g' dissapears and the otherone misses '0' character. I have found out that in debug mode, always the same characters are missing. In release mode it differs across multiple executions. That may relate to the fact, that in DEBUG, all the variables are initialized to 0, whereas in release it will contain some memory trash. But I don't really know...

Thank's

Kris Asick
Member #1,424
July 2001

If you're running in Direct3D mode then it's possible your system is forgetting the contents of video memory when you call al_resize_display(), as Direct3D is specifically designed to discard the contents of video memory when switched away from.

Regardless, the safe thing to do whenever the state of your ALLEGRO_DISPLAY object changes, is to clear all contents of video memory yourself prior, then reload everything afterwards.

Or, you might also try forcing Allegro into OpenGL mode instead as OpenGL doesn't have this problem. This is done with al_set_new_display_flags() when creating the display object.

--- Kris Asick (Gemini)
--- http://www.pixelships.com

Go to: