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

Author Topic: Use of sf::Font's copy constructor?  (Read 2495 times)

0 Members and 1 Guest are viewing this topic.

pdinklag

  • Sr. Member
  • ****
  • Posts: 330
  • JSFML Developer
    • View Profile
    • JSFML Website
Use of sf::Font's copy constructor?
« on: March 16, 2013, 09:39:49 am »
I know Laurent asks for common use cases when asked to introduce new features, now I must ask this for an existing one. :D I just stumbled across sf::Font's copy costructor and can't think of any use case for it.

While copying textures and sounds can make sense, since they are "editable" using update / loadFromSamples, I can't happen to find any use for copying a font. You can't "edit" fonts or glyphs, so there's no use case like "copy that font but change that property". Any copy created would be nothing but wasted memory.

The only uses I found on the forum were a workaround to make something ugly even more ugly (talking about this post) and awkward resource management (= wasted memory, see this post).

So, where is the benefit of this constructor? In essence, why was it implemented?
JSFML - The Java binding to SFML.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Use of sf::Font's copy constructor?
« Reply #1 on: March 16, 2013, 11:58:01 am »
To be honest, I don't remember. Maybe for consistency with other resource classes?
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Use of sf::Font's copy constructor?
« Reply #2 on: March 16, 2013, 12:14:40 pm »
Multi-threaded applications without locking came to my mind, but is it even safe to have two instances of sf::Font, where one is the copy of the other? Because if the font has to load new glyphs, accesses to the original source (file, memory, stream) may happen concurrently...
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

pdinklag

  • Sr. Member
  • ****
  • Posts: 330
  • JSFML Developer
    • View Profile
    • JSFML Website
Re: Use of sf::Font's copy constructor?
« Reply #3 on: March 16, 2013, 01:28:08 pm »
The copy costructor does copy the pixel buffer, but the data source (m_streamRec?) as well as the freetype font data is not. A comment in the implementation notes that freetype does not even support such kind of cloning. The copied font simply gets the pointers to the freetype data shoved into them, so I believe any concurrency issues in reading the source data would remain.
JSFML - The Java binding to SFML.