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

Author Topic: Removed  (Read 1964 times)

0 Members and 1 Guest are viewing this topic.

timl132

  • Guest
Removed
« on: March 18, 2018, 02:41:36 pm »
Removed
« Last Edit: January 08, 2023, 09:16:30 pm by timl132 »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
When a vector gets resized, e.g. when pushing back new elements, then it's reallocated and everything is copied. Since sf::Sprite holds a reference to the texture that gets moved, the reference gets invalidated and you get a white square rendered.

It's better to store textures in a std::map or build something like a resource holder as implemented in Thor: http://www.bromeon.ch/libraries/thor/tutorials/v2.0/resources.html

Also if you use a lot of textures, you might be better of with having one texture with multiple "sprites" on it and then use the sprites texture rect to pick the section of the texture you want.
« Last Edit: March 18, 2018, 03:51:14 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Yes, that's right. When a vector is moved is implementation dependant. Usually a vector would reserve like 1.5x or twice the amount of space that would be needed, so it doesn't have to relocate at every insert.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/