mirror of
https://github.com/SFML/SFML.git
synced 2025-01-19 15:55:13 +08:00
FS#106 - Fixed undefined behaviour when rendering a sprite bound to an empty image
git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1080 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
parent
dafa862481
commit
8a993dca06
@ -49,12 +49,11 @@ myIsFlippedY(false)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Sprite::Sprite(const Image& Img, const Vector2f& Position, const Vector2f& Scale, float Rotation, const Color& Col) :
|
Sprite::Sprite(const Image& Img, const Vector2f& Position, const Vector2f& Scale, float Rotation, const Color& Col) :
|
||||||
Drawable (Position, Scale, Rotation, Col),
|
Drawable (Position, Scale, Rotation, Col),
|
||||||
myImage (&Img),
|
mySubRect (0, 0, 1, 1),
|
||||||
mySubRect (0, 0, Img.GetWidth(), Img.GetHeight()),
|
|
||||||
myIsFlippedX(false),
|
myIsFlippedX(false),
|
||||||
myIsFlippedY(false)
|
myIsFlippedY(false)
|
||||||
{
|
{
|
||||||
|
SetImage(Img);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -63,9 +62,11 @@ myIsFlippedY(false)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void Sprite::SetImage(const Image& Img)
|
void Sprite::SetImage(const Image& Img)
|
||||||
{
|
{
|
||||||
// If there was no source image before, adjust the rectangle
|
// If there was no source image before and the new image is valid, adjust the source rectangle
|
||||||
if (!myImage)
|
if (!myImage && (Img.GetWidth() > 0) && (Img.GetHeight() > 0))
|
||||||
|
{
|
||||||
SetSubRect(IntRect(0, 0, Img.GetWidth(), Img.GetHeight()));
|
SetSubRect(IntRect(0, 0, Img.GetWidth(), Img.GetHeight()));
|
||||||
|
}
|
||||||
|
|
||||||
// Assign the new image
|
// Assign the new image
|
||||||
myImage = &Img;
|
myImage = &Img;
|
||||||
@ -87,10 +88,11 @@ void Sprite::SetSubRect(const IntRect& SubRect)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void Sprite::Resize(float Width, float Height)
|
void Sprite::Resize(float Width, float Height)
|
||||||
{
|
{
|
||||||
if ((mySubRect.GetWidth() > 0) && (mySubRect.GetHeight() > 0))
|
int LocalWidth = mySubRect.GetWidth();
|
||||||
{
|
int LocalHeight = mySubRect.GetHeight();
|
||||||
SetScale(Width / mySubRect.GetWidth(), Height / mySubRect.GetHeight());
|
|
||||||
}
|
if ((LocalWidth > 0) && (LocalHeight > 0))
|
||||||
|
SetScale(Width / LocalWidth, Height / LocalHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -182,9 +184,9 @@ void Sprite::Render(RenderTarget&) const
|
|||||||
float Height = static_cast<float>(mySubRect.GetHeight());
|
float Height = static_cast<float>(mySubRect.GetHeight());
|
||||||
|
|
||||||
// Check if the image is valid
|
// Check if the image is valid
|
||||||
if (myImage)
|
if (myImage && (myImage->GetWidth() > 0) && (myImage->GetHeight() > 0))
|
||||||
{
|
{
|
||||||
// Set the texture
|
// Bind the texture
|
||||||
myImage->Bind();
|
myImage->Bind();
|
||||||
|
|
||||||
// Calculate the texture coordinates
|
// Calculate the texture coordinates
|
||||||
|
Loading…
Reference in New Issue
Block a user