Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: sf::Text missing glyphs [Bug]  (Read 5669 times)

0 Members and 1 Guest are viewing this topic.

Zefz

  • Newbie
  • *
  • Posts: 21
    • View Profile
sf::Text missing glyphs [Bug]
« on: April 28, 2012, 08:05:50 pm »
There is a curious bug in the Text class. When drawing a Text string, certain letters (glyphs) do not appear. They do however appear if I append a new letter that is not in the string already (the new letter does not appear however until I add yet a new letter that does not appear).

I discovered that letters only appear properly once SFML properly generates or caches the glyphs. So my guess is that there is a problem with generating or caching the letters first time they appear.

The following workaround (code snippet placed in the beginning of the program) solves the problem:
   
//loop through all letters we need to cache
for(Uint32 letter = 0x0020; letter < 0x00FF; letter++)
    {
        //cache various font sizes
        for(int size = 12; size < 32; size++)
        {
            Font::getDefaultFont().getGlyph(letter, size, false);
            Font::getDefaultFont().getGlyph(letter, size, true);
        }
    }
 

The code to reproduce this problem is trivial. Use default font (or any other kind of font) of any size and draw it. Certain letters have always problem drawing the first time (until I draw another problem letter, in which case only the new problem letter is not drawn properly).

Windows 7 (64-bit). Compiled SFML in x86 Debug mode using GCC and Code::Blocks. Graphics card is an Nvidia GTX460M.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::Text missing glyphs [Bug]
« Reply #1 on: April 28, 2012, 08:12:15 pm »
I've run a lot of code samples with text, and never experiences such a problem. So you should show a minimal code that reproduces it.
Laurent Gomila - SFML developer

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: sf::Text missing glyphs [Bug]
« Reply #2 on: April 28, 2012, 08:13:14 pm »
Do you use only one thread?
I've experienced similar problems when drawing from diffrent threads but nobody really cared to explain what goes wrong.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Zefz

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: sf::Text missing glyphs [Bug]
« Reply #3 on: April 28, 2012, 09:36:57 pm »
All drawing is done in one thread.

Give me a little time and I will write some code that reproduces the problem.

Zefz

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: sf::Text missing glyphs [Bug]
« Reply #4 on: April 29, 2012, 12:53:58 am »
OK. I've done some more research on the matter. It seems the bug is not consistent. Sometimes the letters are missing and sometimes they are not. I tried various settings and reordering rendering routines but could not connect it to anything specific.

It is still always the same letters that aren't drawn (in the cases they are missing). I will refrain from posting any code until I am certain of what causes the problem.

The default Window example always draws correctly.

Pigyman

  • Newbie
  • *
  • Posts: 1
  • The Pig Man
    • View Profile
    • VGM Radio
Re: sf::Text missing glyphs [Bug]
« Reply #5 on: May 04, 2012, 05:26:34 pm »
I have also encountered the bug.  The bug does not occur under all situations; however, I have gotten it to consistently occur with a simple framerate counter.

Here is the code for SFML.NET:

using System;
using SFML.Window;
using SFML.Graphics;
using System.Timers;

namespace MissingGlyphs
{
    class Program
    {
        static Text text = new Text();
        static Random r = new Random();
        static int frames = 0;
        static RenderWindow app;

        static void Main()
        {
            app = new RenderWindow(new VideoMode(800, 600), "Missing Glyphs");

            app.Closed += new EventHandler(app_Closed);

            text.CharacterSize = 18; //The larger the font, the more issues it has.  Nothing displays at 72.
            text.Position = new Vector2f(4, 4);
            text.Color = Color.White;

            Timer fpsTimer = new Timer();
            fpsTimer.Elapsed += new ElapsedEventHandler(fpsTimer_Elapsed);
            fpsTimer.Interval = 1000;
            fpsTimer.Start();

            while (app.IsOpen())
            {
                frames++;

                app.DispatchEvents();

                app.Clear(Color.Black);

                app.Draw(text);

                app.Display();
            }
        }

        static void fpsTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            text.DisplayedString = frames.ToString() + " FPS";
            app.SetTitle("Missing Glyphs - " + frames.ToString() + " FPS");
            frames = 0;
        }

        static void app_Closed(object sender, EventArgs e)
        {
            app.Close();
        }
    }
}
 

I hope this helps the problem.
« Last Edit: May 04, 2012, 07:01:42 pm by Pigyman »

Zefz

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: sf::Text missing glyphs [Bug]
« Reply #6 on: June 25, 2012, 11:51:56 pm »
I can confirm that this still is a problem.

This is probably the same issue as:
http://en.sfml-dev.org/forums/index.php?topic=2073.msg13545#msg13545

I did some more research and looked into SFML part of the code. The problem seems to be in Font::loadGlyph(). I have determined this by checking if everything above this level was working correctly (the entire Text class seems to be working correctly). Is it possible that it finds something wrong in the glyph cache and returns an empty glyph?

I had a few problems with the program crashing and complaining that Texture size was too big. As mentioned in the forum post I linked above the problem does not appear on text assigned in the constructor, only through setString. Very strange.

Celtic Minstrel

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
Re: sf::Text missing glyphs [Bug]
« Reply #7 on: June 26, 2012, 02:45:30 am »
Do you use only one thread?
I've experienced similar problems when drawing from diffrent threads but nobody really cared to explain what goes wrong.
I did too; I solved it by locking mutexes in my text draw/measure functions, though I'm not sure I really like that solution.

Zefz

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: sf::Text missing glyphs [Bug]
« Reply #8 on: June 28, 2012, 10:07:15 pm »
I've tried adding mutexes as well, but it did not help.

Celtic Minstrel

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
Re: sf::Text missing glyphs [Bug]
« Reply #9 on: June 29, 2012, 01:29:33 am »
Well, to be fair, my issue wasn't missing glyphs but malformed glyphs, so maybe the cause is completely different...

 

anything