Prevent using a temporary sf::Texture with sf::Sprite

This commit is contained in:
Chris Thrasher 2023-01-05 17:40:09 -07:00
parent 0bb6303cf8
commit 0c2f7da9f9
2 changed files with 19 additions and 0 deletions

View File

@ -65,6 +65,12 @@ public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
explicit Sprite(const Texture& texture); explicit Sprite(const Texture& texture);
////////////////////////////////////////////////////////////
/// \brief Disallow construction from a temporary texture
///
////////////////////////////////////////////////////////////
explicit Sprite(Texture&& texture) = delete;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Construct the sprite from a sub-rectangle of a source texture /// \brief Construct the sprite from a sub-rectangle of a source texture
/// ///
@ -76,6 +82,12 @@ public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Sprite(const Texture& texture, const IntRect& rectangle); Sprite(const Texture& texture, const IntRect& rectangle);
////////////////////////////////////////////////////////////
/// \brief Disallow construction from a temporary texture
///
////////////////////////////////////////////////////////////
Sprite(Texture&& texture, const IntRect& rectangle) = delete;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Change the source texture of the sprite /// \brief Change the source texture of the sprite
/// ///
@ -97,6 +109,12 @@ public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void setTexture(const Texture& texture, bool resetRect = false); void setTexture(const Texture& texture, bool resetRect = false);
////////////////////////////////////////////////////////////
/// \brief Disallow setting from a temporary texture
///
////////////////////////////////////////////////////////////
void setTexture(Texture&& texture, bool resetRect = false) = delete;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Set the sub-rectangle of the texture that the sprite will display /// \brief Set the sub-rectangle of the texture that the sprite will display
/// ///

View File

@ -2,6 +2,7 @@
#include <type_traits> #include <type_traits>
static_assert(!std::is_constructible_v<sf::Sprite, sf::Texture&&>);
static_assert(std::is_copy_constructible_v<sf::Sprite>); static_assert(std::is_copy_constructible_v<sf::Sprite>);
static_assert(std::is_copy_assignable_v<sf::Sprite>); static_assert(std::is_copy_assignable_v<sf::Sprite>);
static_assert(std::is_nothrow_move_constructible_v<sf::Sprite>); static_assert(std::is_nothrow_move_constructible_v<sf::Sprite>);