From b25bf7633014532578bfada380a634b80f6d82d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Sat, 31 May 2014 21:58:18 -0300 Subject: [PATCH] Minor fixes! --- src/eepp/gaming/cmap.cpp | 16 ++++--- src/eepp/graphics/cconsole.cpp | 2 +- src/eepp/graphics/cimage.cpp | 3 +- src/eepp/graphics/cparticlesystem.cpp | 2 +- src/eepp/graphics/csprite.cpp | 12 ++++-- src/eepp/graphics/csubtexture.cpp | 2 +- src/eepp/graphics/ctexturepacker.cpp | 16 ++++--- src/eepp/ui/cuicontrol.cpp | 48 ++++++++++++--------- src/eepp/ui/cuimanager.cpp | 2 + src/eepp/ui/cuitextbox.cpp | 2 +- src/eepp/window/platform/x11/ccursorx11.cpp | 2 +- 11 files changed, 63 insertions(+), 44 deletions(-) diff --git a/src/eepp/gaming/cmap.cpp b/src/eepp/gaming/cmap.cpp index ed0178bf9..708cbaf7a 100644 --- a/src/eepp/gaming/cmap.cpp +++ b/src/eepp/gaming/cmap.cpp @@ -873,17 +873,19 @@ bool cMap::LoadFromStream( cIOStream& IOS ) { cLayer * tLayer = AddLayer( tLayerHdr->Type, tLayerHdr->Flags, std::string( tLayerHdr->Name ) ); - tLayer->Offset( eeVector2f( (eeFloat)tLayerHdr->OffsetX, (eeFloat)tLayerHdr->OffsetY ) ); + if ( NULL != tLayer ) { + tLayer->Offset( eeVector2f( (eeFloat)tLayerHdr->OffsetX, (eeFloat)tLayerHdr->OffsetY ) ); - sPropertyHdr * tProps = eeNewArray( sPropertyHdr, tLayerHdr->PropertyCount ); + sPropertyHdr * tProps = eeNewArray( sPropertyHdr, tLayerHdr->PropertyCount ); - IOS.Read( (char*)&tProps[0], sizeof(sPropertyHdr) * tLayerHdr->PropertyCount ); + IOS.Read( (char*)&tProps[0], sizeof(sPropertyHdr) * tLayerHdr->PropertyCount ); - for ( z = 0; z < tLayerHdr->PropertyCount; z++ ) { - tLayer->AddProperty( std::string( tProps[z].Name ), std::string( tProps[z].Value ) ); + for ( z = 0; z < tLayerHdr->PropertyCount; z++ ) { + tLayer->AddProperty( std::string( tProps[z].Name ), std::string( tProps[z].Value ) ); + } + + eeSAFE_DELETE_ARRAY( tProps ); } - - eeSAFE_DELETE_ARRAY( tProps ); } bool ThereIsTiled = false; diff --git a/src/eepp/graphics/cconsole.cpp b/src/eepp/graphics/cconsole.cpp index 800db44b8..9db0957d7 100755 --- a/src/eepp/graphics/cconsole.cpp +++ b/src/eepp/graphics/cconsole.cpp @@ -219,7 +219,7 @@ void cConsole::Draw() { } } - if ( mShowFps ) { + if ( mShowFps && NULL != mFont ) { eeColorA OldColor1( mFont->Color() ); mFont->Color( eeColorA () ); mFont->SetText( "FPS: " + String::ToStr( mWindow->FPS() ) ); diff --git a/src/eepp/graphics/cimage.cpp b/src/eepp/graphics/cimage.cpp index 4d6e25f50..0d9270494 100644 --- a/src/eepp/graphics/cimage.cpp +++ b/src/eepp/graphics/cimage.cpp @@ -428,7 +428,8 @@ eeSize cImage::Size() { void cImage::ClearCache() { if ( mLoadedFromStbi ) { - free( mPixels ); + if ( NULL != mPixels ) + free( mPixels ); } else { eeSAFE_DELETE_ARRAY( mPixels ); } diff --git a/src/eepp/graphics/cparticlesystem.cpp b/src/eepp/graphics/cparticlesystem.cpp index c0e5418c8..154d57bbb 100755 --- a/src/eepp/graphics/cparticlesystem.cpp +++ b/src/eepp/graphics/cparticlesystem.cpp @@ -113,7 +113,7 @@ void cParticleSystem::Reset( cParticle * P ) { x = ( mPos2.x - mPos.x + 1 ) * Math::Randf() + mPos.x; y = ( mPos2.y - mPos.y + 1 ) * Math::Randf() + mPos.y; - P->Reset( mPos.x, mPos.y, Math::Randf() - 0.5f, ( Math::Randf() - 1.1f ) * 8.5f, 0.f, 0.05f, mSize ); + P->Reset( x, y, Math::Randf() - 0.5f, ( Math::Randf() - 1.1f ) * 8.5f, 0.f, 0.05f, mSize ); P->Color( eeColorAf( 1.f, 0.5f, 0.1f, ( Math::Randf() * 0.5f ) ), Math::Randf() * 0.4f + 0.01f ); break; } diff --git a/src/eepp/graphics/csprite.cpp b/src/eepp/graphics/csprite.cpp index b431ace87..51393f25b 100755 --- a/src/eepp/graphics/csprite.cpp +++ b/src/eepp/graphics/csprite.cpp @@ -419,12 +419,16 @@ bool cSprite::AddSubFrame( cSubTexture * SubTexture, const eeUint& NumFrame, con else NSF = NumSubFrame; - if ( mFrames[NF].Spr.size() != (eeUint)mSubFrames ) - mFrames[NF].Spr.resize( mSubFrames ); + if ( NF <= mFrames.size() ) { + if ( mFrames[NF].Spr.size() != (eeUint)mSubFrames ) + mFrames[NF].Spr.resize( mSubFrames ); - mFrames[NF].Spr[NSF] = SubTexture; + mFrames[NF].Spr[NSF] = SubTexture; - return true; + return true; + } + + return false; } eeUint cSprite::AddFrame( cSubTexture * SubTexture ) { diff --git a/src/eepp/graphics/csubtexture.cpp b/src/eepp/graphics/csubtexture.cpp index 91e2ed5f5..127963c0a 100644 --- a/src/eepp/graphics/csubtexture.cpp +++ b/src/eepp/graphics/csubtexture.cpp @@ -304,7 +304,7 @@ Uint8 * cSubTexture::Lock() { } bool cSubTexture::Unlock( const bool& KeepData, const bool& Modified ) { - if ( NULL != mPixels ) { + if ( NULL != mPixels && NULL != mTexture ) { if ( Modified ) { cTextureSaver saver( mTexture->Handle() ); diff --git a/src/eepp/graphics/ctexturepacker.cpp b/src/eepp/graphics/ctexturepacker.cpp index 7465ce0e7..3bdbde055 100644 --- a/src/eepp/graphics/ctexturepacker.cpp +++ b/src/eepp/graphics/ctexturepacker.cpp @@ -105,7 +105,7 @@ bool cTexturePacker::MergeNodes() { cTexturePackerNode *f = mFreeList; while ( f ) { - cTexturePackerNode * prev = 0; + cTexturePackerNode * prev = NULL; cTexturePackerNode * c = mFreeList; while ( c ) { @@ -113,7 +113,9 @@ bool cTexturePacker::MergeNodes() { if ( f->Merge( *c ) ) { eeASSERT( prev ); - prev->SetNext( c->GetNext() ); + if ( NULL != prev ) { + prev->SetNext( c->GetNext() ); + } eeSAFE_DELETE( c ); @@ -732,11 +734,13 @@ void cTexturePacker::ChildSave( const EE_SAVE_TYPE& Format ) { Parent = Parent->GetParent(); } - std::string fFpath = FileSystem::FileRemoveExtension( LastParent->GetFilepath() ); - std::string fExt = FileSystem::FileExtension( LastParent->GetFilepath() ); - std::string fName = fFpath + "_ch" + String::ToStr( ParentCount ) + "." + fExt; + if ( NULL != LastParent ) { + std::string fFpath = FileSystem::FileRemoveExtension( LastParent->GetFilepath() ); + std::string fExt = FileSystem::FileExtension( LastParent->GetFilepath() ); + std::string fName = fFpath + "_ch" + String::ToStr( ParentCount ) + "." + fExt; - mChild->Save( fName, Format, mSaveExtensions ); + mChild->Save( fName, Format, mSaveExtensions ); + } } } diff --git a/src/eepp/ui/cuicontrol.cpp b/src/eepp/ui/cuicontrol.cpp index 0a68c3cb9..474c72148 100644 --- a/src/eepp/ui/cuicontrol.cpp +++ b/src/eepp/ui/cuicontrol.cpp @@ -642,6 +642,8 @@ void cUIControl::ChildAdd( cUIControl * ChildCtrl ) { } void cUIControl::ChildAddAt( cUIControl * ChildCtrl, Uint32 Pos ) { + eeASSERT( NULL != ChildCtrl ); + cUIControl * ChildLoop = mChild; ChildCtrl->Parent( this ); @@ -649,32 +651,36 @@ void cUIControl::ChildAddAt( cUIControl * ChildCtrl, Uint32 Pos ) { ChildRemove( ChildCtrl ); ChildCtrl->mParentCtrl = this; - if( Pos == 0 ) { - if ( mChild == NULL ) { - mChild = ChildCtrl; - mChildLast = ChildCtrl; - ChildCtrl->mNext = NULL; - ChildCtrl->mPrev = NULL; - } else { + if ( ChildLoop == NULL ) { + mChild = ChildCtrl; + mChildLast = ChildCtrl; + ChildCtrl->mNext = NULL; + ChildCtrl->mPrev = NULL; + } else { + if( Pos == 0 ) { mChild->mPrev = ChildCtrl; ChildCtrl->mNext = mChild; ChildCtrl->mPrev = NULL; mChild = ChildCtrl; + } else { + Uint32 i = 0; + + while ( NULL != ChildLoop->mNext && i < Pos ) { + ChildLoop = ChildLoop->mNext; + i++; + } + + cUIControl * ChildTmp = ChildLoop->mNext; + ChildLoop->mNext = ChildCtrl; + ChildCtrl->mPrev = ChildLoop; + ChildCtrl->mNext = ChildTmp; + + if ( NULL != ChildTmp ) { + ChildTmp->mPrev = ChildCtrl; + } else { + mChildLast = ChildCtrl; + } } - } else { - Uint32 i = 0; - - while ( NULL != ChildLoop->mNext && i < Pos ) { - ChildLoop = ChildLoop->mNext; - i++; - } - - cUIControl * ChildTmp = ChildLoop->mNext; - ChildLoop->mNext = ChildCtrl; - ChildCtrl->mPrev = ChildLoop; - - ChildCtrl->mNext = ChildTmp; - ChildTmp->mPrev = ChildCtrl; } } diff --git a/src/eepp/ui/cuimanager.cpp b/src/eepp/ui/cuimanager.cpp index 5922162b7..2a59bc61a 100644 --- a/src/eepp/ui/cuimanager.cpp +++ b/src/eepp/ui/cuimanager.cpp @@ -326,6 +326,8 @@ const eeColorA& cUIManager::HighlightOverColor() const { } void cUIManager::CheckTabPress( const Uint32& KeyCode ) { + eeASSERT( NULL != mFocusControl ); + if ( KeyCode == KEY_TAB ) { cUIControl * Ctrl = mFocusControl->NextComplexControl(); diff --git a/src/eepp/ui/cuitextbox.cpp b/src/eepp/ui/cuitextbox.cpp index 14d69aaaa..1c89fab05 100644 --- a/src/eepp/ui/cuitextbox.cpp +++ b/src/eepp/ui/cuitextbox.cpp @@ -315,7 +315,7 @@ void cUITextBox::DrawSelection() { return; } - Int32 lastEnd = end; + Int32 lastEnd; eeVector2i initPos, endPos; cPrimitives P; diff --git a/src/eepp/window/platform/x11/ccursorx11.cpp b/src/eepp/window/platform/x11/ccursorx11.cpp index b1650ebe0..ff5264ff0 100644 --- a/src/eepp/window/platform/x11/ccursorx11.cpp +++ b/src/eepp/window/platform/x11/ccursorx11.cpp @@ -41,7 +41,7 @@ cCursorX11::~cCursorX11() { } void cCursorX11::Create() { - if ( NULL == mImage && mImage->MemSize() ) + if ( NULL == mImage || 0 == mImage->MemSize() ) return; XcursorImage * image;