Welcome,
Guest
. Please
login
or
register
. Did you miss your
activation email?
French forum
Home
Help
Search
Login
Register
SFML community forums
»
Help
»
Graphics
»
Removed
Print
Pages: [
1
]
Author
Topic: Removed (Read 1970 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
»
Logged
eXpl0it3r
SFML Team
Hero Member
Posts: 11034
Re: My texture remembering class with sf::Texture doesn't work correct, help?
«
Reply #1 on:
March 18, 2018, 03:36:34 pm »
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
»
Logged
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: 11034
Re: My texture remembering class with sf::Texture doesn't work correct, help?
«
Reply #2 on:
March 18, 2018, 07:16:42 pm »
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.
Logged
Official FAQ:
https://www.sfml-dev.org/faq.php
Official Discord Server:
https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog:
https://duerrenberger.dev/blog/
Print
Pages: [
1
]
SFML community forums
»
Help
»
Graphics
»
Removed
anything