@ -60,7 +60,7 @@ Push_back on the vector will make a copy of aSprite in the vector and then aSpri
The copy constructor for MySprite does not load a new texture, it just copies the ID values from the source texture.
The copy constructor for MySprite does not load a new texture, it just copies the ID values from the source texture.
So then you have (for a short time) two objects that point to the same texture. When aSprite goes out of scope, it will call UnloadTexture and remove the texture ID from the GPU. So now you have a copy of the sprite in the container that points to an unloaded texture. This will not work for drawing.
So then you have (for a short time) two objects that point to the same texture. When aSprite goes out of scope, it will call UnloadTexture and remove the texture ID from the GPU. So now you have a copy of the sprite in the container that points to an unloaded texture. This will not work for drawing.
If you want to use this pattern, you need to ensure that you don't make copies of things that contain shared resources. The simplest way to handle this is to remove the assignment and copy constructor operators and use std::move or emplace features to ensue that the container owns the data and manages the lifetime.
If you want to use this pattern, you need to ensure that you don't make copies of things that contain shared resources. The simplest way to handle this is to remove the assignment and copy constructor operators and use std::move or emplace features to ensure that the container owns the data and manages the lifetime.