mirror of
https://github.com/SFML/SFML.git
synced 2024-11-25 12:51:05 +08:00
Fixed crash when creating an empty sf::Image
This commit is contained in:
parent
5207930169
commit
ac43578f75
@ -45,22 +45,32 @@ m_size(0, 0)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void Image::create(unsigned int width, unsigned int height, const Color& color)
|
void Image::create(unsigned int width, unsigned int height, const Color& color)
|
||||||
{
|
{
|
||||||
// Assign the new size
|
if (width && height)
|
||||||
m_size.x = width;
|
|
||||||
m_size.y = height;
|
|
||||||
|
|
||||||
// Resize the pixel buffer
|
|
||||||
m_pixels.resize(width * height * 4);
|
|
||||||
|
|
||||||
// Fill it with the specified color
|
|
||||||
Uint8* ptr = &m_pixels[0];
|
|
||||||
Uint8* end = ptr + m_pixels.size();
|
|
||||||
while (ptr < end)
|
|
||||||
{
|
{
|
||||||
*ptr++ = color.r;
|
// Assign the new size
|
||||||
*ptr++ = color.g;
|
m_size.x = width;
|
||||||
*ptr++ = color.b;
|
m_size.y = height;
|
||||||
*ptr++ = color.a;
|
|
||||||
|
// Resize the pixel buffer
|
||||||
|
m_pixels.resize(width * height * 4);
|
||||||
|
|
||||||
|
// Fill it with the specified color
|
||||||
|
Uint8* ptr = &m_pixels[0];
|
||||||
|
Uint8* end = ptr + m_pixels.size();
|
||||||
|
while (ptr < end)
|
||||||
|
{
|
||||||
|
*ptr++ = color.r;
|
||||||
|
*ptr++ = color.g;
|
||||||
|
*ptr++ = color.b;
|
||||||
|
*ptr++ = color.a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Create an empty image
|
||||||
|
m_size.x = 0;
|
||||||
|
m_size.y = 0;
|
||||||
|
m_pixels.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,7 +78,7 @@ void Image::create(unsigned int width, unsigned int height, const Color& color)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void Image::create(unsigned int width, unsigned int height, const Uint8* pixels)
|
void Image::create(unsigned int width, unsigned int height, const Uint8* pixels)
|
||||||
{
|
{
|
||||||
if (pixels)
|
if (pixels && width && height)
|
||||||
{
|
{
|
||||||
// Assign the new size
|
// Assign the new size
|
||||||
m_size.x = width;
|
m_size.x = width;
|
||||||
|
Loading…
Reference in New Issue
Block a user