From 5dbb93510263fa575ea736bb6114ae4ba5f139cb Mon Sep 17 00:00:00 2001 From: spartanj Date: Tue, 13 Jul 2010 02:45:29 -0300 Subject: [PATCH] Fixed two huge memory leaks. Next time i'll sleep before programming. :P --- Makefile | 2 -- src/graphics/base.hpp | 2 +- src/graphics/cshape.cpp | 40 ++++++++++++++++---------------- src/graphics/cshape.hpp | 16 ++++++------- src/graphics/ctexture.cpp | 6 ++--- src/graphics/ctexture.hpp | 12 +++++----- src/graphics/ctexturefactory.cpp | 10 +++++--- src/helper/haikuttf/hkbase.hpp | 1 + src/helper/haikuttf/hkglyph.cpp | 5 ++-- 9 files changed, 49 insertions(+), 45 deletions(-) diff --git a/Makefile b/Makefile index bc03b7391..18b90300d 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,3 @@ -export DEBUGBUILD=yes - ifeq ($(DEBUGBUILD), yes) DEBUGFLAGS = -g -DDEBUG -DEE_DEBUG else diff --git a/src/graphics/base.hpp b/src/graphics/base.hpp index 9d90a421f..c7890736d 100644 --- a/src/graphics/base.hpp +++ b/src/graphics/base.hpp @@ -27,6 +27,6 @@ using namespace EE::System; #include "renders.hpp" -#define ALLOC_VECTORS +//#define ALLOC_VECTORS #endif diff --git a/src/graphics/cshape.cpp b/src/graphics/cshape.cpp index 55589b8de..b78f47ae7 100644 --- a/src/graphics/cshape.cpp +++ b/src/graphics/cshape.cpp @@ -5,6 +5,10 @@ namespace EE { namespace Graphics { cShape::cShape() : + #ifndef ALLOC_VECTORS + mPixels(NULL), + mAlpha(NULL), + #endif mId(0), mTexId(0), mTexture(NULL), @@ -14,14 +18,14 @@ cShape::cShape() : mOffSetX(0), mOffSetY(0) { - #ifndef ALLOC_VECTORS - mPixels = NULL; - mAlpha = NULL; - #endif CreateUnnamed(); } cShape::cShape( const Uint32& TexId, const std::string& Name ) : + #ifndef ALLOC_VECTORS + mPixels(NULL), + mAlpha(NULL), + #endif mName( Name ), mId( MakeHash( mName ) ), mTexId( TexId ), @@ -32,13 +36,13 @@ cShape::cShape( const Uint32& TexId, const std::string& Name ) : mOffSetX(0), mOffSetY(0) { - #ifndef ALLOC_VECTORS - mPixels = NULL; - mAlpha = NULL; - #endif } cShape::cShape( const Uint32& TexId, const eeRecti& SrcRect, const std::string& Name ) : + #ifndef ALLOC_VECTORS + mPixels(NULL), + mAlpha(NULL), + #endif mName( Name ), mId( MakeHash( mName ) ), mTexId( TexId ), @@ -49,13 +53,13 @@ cShape::cShape( const Uint32& TexId, const eeRecti& SrcRect, const std::string& mOffSetX(0), mOffSetY(0) { - #ifndef ALLOC_VECTORS - mPixels = NULL; - mAlpha = NULL; - #endif } cShape::cShape( const Uint32& TexId, const eeRecti& SrcRect, const eeFloat& DestWidth, const eeFloat& DestHeight, const std::string& Name ) : + #ifndef ALLOC_VECTORS + mPixels(NULL), + mAlpha(NULL), + #endif mName( Name ), mId( MakeHash( mName ) ), mTexId( TexId ), @@ -66,13 +70,13 @@ cShape::cShape( const Uint32& TexId, const eeRecti& SrcRect, const eeFloat& Dest mOffSetX(0), mOffSetY(0) { - #ifndef ALLOC_VECTORS - mPixels = NULL; - mAlpha = NULL; - #endif } cShape::cShape( const Uint32& TexId, const eeRecti& SrcRect, const eeFloat& DestWidth, const eeFloat& DestHeight, const eeFloat& OffsetX, const eeFloat& OffsetY, const std::string& Name ) : + #ifndef ALLOC_VECTORS + mPixels(NULL), + mAlpha(NULL), + #endif mName( Name ), mId( MakeHash( mName ) ), mTexId( TexId ), @@ -83,10 +87,6 @@ cShape::cShape( const Uint32& TexId, const eeRecti& SrcRect, const eeFloat& Dest mOffSetX(OffsetX), mOffSetY(OffsetY) { - #ifndef ALLOC_VECTORS - mPixels = NULL; - mAlpha = NULL; - #endif } cShape::~cShape() { diff --git a/src/graphics/cshape.hpp b/src/graphics/cshape.hpp index 2928db081..12f311019 100644 --- a/src/graphics/cshape.hpp +++ b/src/graphics/cshape.hpp @@ -87,6 +87,14 @@ class EE_API cShape { bool SaveToFile(const std::string& filepath, const EE_SAVETYPE& Format); protected: + #ifndef ALLOC_VECTORS + eeColorA * mPixels; + Uint8 * mAlpha; + #else + std::vector mPixels; + std::vector mAlpha; + #endif + std::string mName; Uint32 mId; Uint32 mTexId; @@ -97,14 +105,6 @@ class EE_API cShape { eeFloat mOffSetX; eeFloat mOffSetY; - #ifndef ALLOC_VECTORS - eeColorA * mPixels; - Uint8 * mAlpha; - #else - std::vector mPixels; - std::vector mAlpha; - #endif - void CreateUnnamed(); }; diff --git a/src/graphics/ctexture.cpp b/src/graphics/ctexture.cpp index 7c32efcb1..0bd0163b4 100755 --- a/src/graphics/ctexture.cpp +++ b/src/graphics/ctexture.cpp @@ -4,6 +4,9 @@ namespace EE { namespace Graphics { cTexture::cTexture() : + #ifndef ALLOC_VECTORS + mPixels(NULL), + #endif mFilepath(""), mId(0), mTexture(0), @@ -21,9 +24,6 @@ cTexture::cTexture() : mLocked(false), mGrabed(false) { - #ifndef ALLOC_VECTORS - mPixels = NULL; - #endif } cTexture::cTexture( const cTexture& Copy ) : diff --git a/src/graphics/ctexture.hpp b/src/graphics/ctexture.hpp index 6f655a209..03584fe63 100755 --- a/src/graphics/ctexture.hpp +++ b/src/graphics/ctexture.hpp @@ -216,6 +216,12 @@ class EE_API cTexture { /** @return The texture factory internal id of the texture */ const Uint32& TexId() const; protected: + #ifndef ALLOC_VECTORS + eeColorA * mPixels; + #else + std::vector mPixels; + #endif + std::string mFilepath; Uint32 mId; @@ -240,12 +246,6 @@ class EE_API cTexture { bool mLocked; bool mGrabed; - #ifndef ALLOC_VECTORS - eeColorA * mPixels; - #else - std::vector mPixels; - #endif - void ApplyClampMode(); void Allocate( const Uint32& size ); }; diff --git a/src/graphics/ctexturefactory.cpp b/src/graphics/ctexturefactory.cpp index ab653d4a3..81b567eef 100755 --- a/src/graphics/ctexturefactory.cpp +++ b/src/graphics/ctexturefactory.cpp @@ -82,9 +82,13 @@ Uint32 cTextureFactory::LoadFromMemory( const unsigned char* Surface, const eeUi unsigned char * PixelsPtr = SOIL_load_image_from_memory(Surface, Size, &ImgWidth, &ImgHeight, &ImgChannels, SOIL_LOAD_AUTO); - if ( NULL != PixelsPtr ) - return LoadFromPixels( PixelsPtr, ImgWidth, ImgHeight, ImgChannels, mipmap, ColorKey, ClampMode, CompressTexture, KeepLocalCopy ); - else + if ( NULL != PixelsPtr ) { + Uint32 Result = LoadFromPixels( PixelsPtr, ImgWidth, ImgHeight, ImgChannels, mipmap, ColorKey, ClampMode, CompressTexture, KeepLocalCopy ); + + SOIL_free_image_data( PixelsPtr ); + + return Result; + } else Log->Write( SOIL_last_result() ); return 0; diff --git a/src/helper/haikuttf/hkbase.hpp b/src/helper/haikuttf/hkbase.hpp index 8132b6b12..2516b1ad0 100644 --- a/src/helper/haikuttf/hkbase.hpp +++ b/src/helper/haikuttf/hkbase.hpp @@ -41,6 +41,7 @@ namespace HaikuTTF { #define hkARRAY_SIZE(__array) ( sizeof(__array) / sizeof(__array[0]) ) #define hkSAFE_DELETE(p) { if(p) { delete (p); (p)=NULL; } } +#define hkSAFE_FREE(p) { if(p) { free (p); (p)=NULL; } } #define hkSAFE_DELETE_ARRAY(p) { if(p) { delete[](p); (p)=NULL; } } #define HK_GETSET( __TYPE, __NAME ) \ diff --git a/src/helper/haikuttf/hkglyph.cpp b/src/helper/haikuttf/hkglyph.cpp index 84cc61936..0e0b381a5 100644 --- a/src/helper/haikuttf/hkglyph.cpp +++ b/src/helper/haikuttf/hkglyph.cpp @@ -18,14 +18,15 @@ hkGlyph::hkGlyph() : } hkGlyph::~hkGlyph() { + Flush(); } void hkGlyph::Flush() { mStored = 0; mIndex = 0; - hkSAFE_DELETE_ARRAY( mBitmap.buffer ); - //hkSAFE_DELETE_ARRAY( mPixmap.buffer ); + hkSAFE_FREE( mBitmap.buffer ); + hkSAFE_FREE( mPixmap.buffer ); mCached = 0; }