Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Sprite: move freePixels ivar to base

pixels is assumed to be owned by the base class unless freePixels is false
  • Loading branch information...
commit f35159f6c7ff4941fbcd2d5f7c13b0ae8bd7f7d3 1 parent da0e66e
@bradallred bradallred authored
View
6 gemrb/core/Sprite2D.cpp
@@ -31,6 +31,7 @@ const TypeID Sprite2D::ID = { "Sprite2D" };
Sprite2D::Sprite2D(int Width, int Height, int Bpp, const void* pixels)
: Width(Width), Height(Height), Bpp(Bpp), pixels(pixels)
{
+ freePixels = true;
BAM = false;
RLE = false;
XPos = 0;
@@ -52,10 +53,15 @@ Sprite2D::Sprite2D(const Sprite2D &obj)
Bpp = obj.Bpp;
pixels = obj.pixels;
+ freePixels = false;
}
Sprite2D::~Sprite2D()
{
+ if (freePixels && pixels) {
+ // FIXME: casting away const.
+ free((void*)pixels);
+ }
}
bool Sprite2D::IsPixelTransparent(unsigned short x, unsigned short y) const
View
2  gemrb/core/Sprite2D.h
@@ -51,6 +51,8 @@ class GEM_EXPORT Sprite2D {
static const TypeID ID;
private:
int RefCount;
+protected:
+ bool freePixels;
public:
int XPos, YPos, Width, Height, Bpp;
View
2  gemrb/plugins/BAMImporter/BAMSprite2D.cpp
@@ -36,6 +36,7 @@ BAMSprite2D::BAMSprite2D(int Width, int Height, const void* pixels,
source = datasrc;
datasrc->IncDataRefCount();
BAM = true;
+ freePixels = false; // managed by datasrc
}
BAMSprite2D::BAMSprite2D(const BAMSprite2D &obj)
@@ -51,6 +52,7 @@ BAMSprite2D::BAMSprite2D(const BAMSprite2D &obj)
source = obj.source;
source->IncDataRefCount();
BAM = true;
+ freePixels = false; // managed by datasrc
}
BAMSprite2D* BAMSprite2D::copy() const
View
6 gemrb/plugins/SDLVideo/SDLSurfaceSprite2D.cpp
@@ -32,7 +32,6 @@ SDLSurfaceSprite2D::SDLSurfaceSprite2D (int Width, int Height, int Bpp, void* pi
{
surface = SDL_CreateRGBSurfaceFrom( pixels, Width, Height, Bpp < 8 ? 8 : Bpp, Width * ( Bpp / 8 ),
rmask, gmask, bmask, amask );
- freePixels = true;
SetSurfaceRLE(true);
}
@@ -41,7 +40,6 @@ SDLSurfaceSprite2D::SDLSurfaceSprite2D(const SDLSurfaceSprite2D &obj)
{
surface = SDL_ConvertSurface(obj.surface, obj.surface->format, obj.surface->flags);
pixels = surface->pixels;
- freePixels = false;
SetSurfaceRLE(obj.RLE);
}
@@ -53,10 +51,6 @@ SDLSurfaceSprite2D* SDLSurfaceSprite2D::copy() const
SDLSurfaceSprite2D::~SDLSurfaceSprite2D()
{
SDL_FreeSurface(surface);
- if (freePixels) {
- // FIXME: casting away const.
- free((void*)pixels);
- }
}
/** Get the Palette of a Sprite */
View
1  gemrb/plugins/SDLVideo/SDLSurfaceSprite2D.h
@@ -30,7 +30,6 @@ namespace GemRB {
class SDLSurfaceSprite2D : public Sprite2D {
private:
- bool freePixels;
SDL_Surface* surface;
private:
void SetSurfaceRLE(bool);
Please sign in to comment.
Something went wrong with that request. Please try again.