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

Author Topic: Loading sf::Font from memory doesn't copy the data, why?  (Read 1199 times)

0 Members and 1 Guest are viewing this topic.

kdunee

  • Newbie
  • *
  • Posts: 6
    • View Profile
Loading sf::Font from memory doesn't copy the data, why?
« on: July 24, 2013, 03:55:49 pm »
Is there a serious reason for not copying the data into sf::Font, like every other resource type does?
Not that it's a major problem, but it feels inconsistent with the rest of the library. With Shader, Texture, SoundBuffer, Music I can just pass the buffer and delete it afterwards.

In the documentation it reads:
Warning: SFML cannot preload all the font data in this function, so the buffer pointed by data has to remain valid as long as the font is used.

Perhaps it could just make a dumb copy of the buffer and store it, so that we could delete the original?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Loading sf::Font from memory doesn't copy the data, why?
« Reply #1 on: July 24, 2013, 04:03:40 pm »
Other resources can be fully loaded and not require the source file after that. Since fonts can contain hundreds of thousands of glyphs, and at this point the sf::Font instance doesn't know which ones you'll need for your sf::Texts, you can easily understand that loading everything is not an option, therefore the source file is required as long as you load new glyphs.

Note that sf::Music works the same way. You must keep your source buffer after loading it, it is used during play.
Laurent Gomila - SFML developer

kdunee

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Loading sf::Font from memory doesn't copy the data, why?
« Reply #2 on: July 24, 2013, 04:17:09 pm »
Thanks Laurent, I forgot the sf::Music. With two justified cases it's fine by me   ;)

 

anything