From 9483ecdfefbaff3612b096b73a301e0afeaf06f2 Mon Sep 17 00:00:00 2001 From: LaurentGom Date: Sat, 3 Oct 2009 14:48:54 +0000 Subject: [PATCH] Fixed copy constructor in sf::Image (didn't properly copy the pixels when the source image was a RenderImage) git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1228 4e206d99-4929-0410-ac5d-dfc041789085 --- src/SFML/Graphics/Image.cpp | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/SFML/Graphics/Image.cpp b/src/SFML/Graphics/Image.cpp index 8b9570055..7920b32b2 100644 --- a/src/SFML/Graphics/Image.cpp +++ b/src/SFML/Graphics/Image.cpp @@ -60,18 +60,24 @@ myPixelsFlipped (false) /// Copy constructor //////////////////////////////////////////////////////////// Image::Image(const Image& copy) : -Resource (copy), -myWidth (copy.myWidth), -myHeight (copy.myHeight), -myTextureWidth (copy.myTextureWidth), -myTextureHeight (copy.myTextureHeight), -myTexture (0), -myIsSmooth (copy.myIsSmooth), -myPixels (copy.myPixels), -myNeedTextureUpdate(false), -myNeedArrayUpdate (false), -myPixelsFlipped (copy.myPixelsFlipped) +Resource(copy) { + // First make sure that the source image is up-to-date + const_cast(copy).EnsureArrayUpdate(); + + // Copy all its members + myWidth = copy.myWidth; + myHeight = copy.myHeight; + myTextureWidth = copy.myTextureWidth; + myTextureHeight = copy.myTextureHeight; + myTexture = 0; + myIsSmooth = copy.myIsSmooth; + myPixels = copy.myPixels; + myNeedTextureUpdate = false; + myNeedArrayUpdate = false; + myPixelsFlipped = copy.myPixelsFlipped; + + // Create the texture CreateTexture(); }