From 0c2f7da9f93348734ec80e9d3d7514e32e8a02c8 Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Thu, 5 Jan 2023 17:40:09 -0700 Subject: [PATCH] Prevent using a temporary `sf::Texture` with `sf::Sprite` --- include/SFML/Graphics/Sprite.hpp | 18 ++++++++++++++++++ test/Graphics/Sprite.test.cpp | 1 + 2 files changed, 19 insertions(+) diff --git a/include/SFML/Graphics/Sprite.hpp b/include/SFML/Graphics/Sprite.hpp index 7f5f7c29..d191a0ec 100644 --- a/include/SFML/Graphics/Sprite.hpp +++ b/include/SFML/Graphics/Sprite.hpp @@ -65,6 +65,12 @@ public: //////////////////////////////////////////////////////////// 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 /// @@ -76,6 +82,12 @@ public: //////////////////////////////////////////////////////////// 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 /// @@ -97,6 +109,12 @@ public: //////////////////////////////////////////////////////////// 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 /// diff --git a/test/Graphics/Sprite.test.cpp b/test/Graphics/Sprite.test.cpp index 3f74ed00..f10b9f8c 100644 --- a/test/Graphics/Sprite.test.cpp +++ b/test/Graphics/Sprite.test.cpp @@ -2,6 +2,7 @@ #include +static_assert(!std::is_constructible_v); static_assert(std::is_copy_constructible_v); static_assert(std::is_copy_assignable_v); static_assert(std::is_nothrow_move_constructible_v);