From 774fc2e65fa81c9dbd9e80dc600832f03feeaaa2 Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Thu, 6 Jun 2024 15:42:06 -0600 Subject: [PATCH] Protect against drawing a sprite when the underlying texture has been moved Inspired by #3062. If you construct a texture and a sprite then move the sprite, the sprite is left pointing at an address where there is no longer a usable texture. The texture's lifetime has not yet ended, however the texture is in a moved-from state and thus it's not suitable to draw the sprite. Doing so will result in unintended and undesirable effects. --- src/SFML/Graphics/Sprite.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/SFML/Graphics/Sprite.cpp b/src/SFML/Graphics/Sprite.cpp index 21db6ef17..a4c88fdc7 100644 --- a/src/SFML/Graphics/Sprite.cpp +++ b/src/SFML/Graphics/Sprite.cpp @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -128,6 +129,8 @@ FloatRect Sprite::getGlobalBounds() const //////////////////////////////////////////////////////////// void Sprite::draw(RenderTarget& target, RenderStates states) const { + assert(m_texture->getNativeHandle() != 0 && "Sprite::draw() Cannot draw sprite when texture is not initialized"); + states.transform *= getTransform(); states.texture = m_texture; states.coordinateType = CoordinateType::Pixels;