From 031f2dbffba461072f130c31ea71eebe4abca22e Mon Sep 17 00:00:00 2001 From: Tobias Loose Date: Fri, 29 Nov 2013 18:20:41 +0100 Subject: [PATCH 1/2] Fix Valgrind warnings appearing during the test suit. --- JGE/src/JGfx-fake.cpp | 4 +--- JGE/src/pc/JGfx.cpp | 2 +- projects/mtg/include/AllAbilities.h | 1 + projects/mtg/src/ActionStack.cpp | 1 + projects/mtg/src/AllAbilities.cpp | 7 +++++++ projects/mtg/src/CardPrimitive.cpp | 3 +++ projects/mtg/src/CardSelector.cpp | 2 +- projects/mtg/src/GameOptions.cpp | 2 +- projects/mtg/src/MTGAbility.cpp | 3 +++ projects/mtg/src/MTGCardInstance.cpp | 3 +++ projects/mtg/src/StyleManager.cpp | 2 +- 11 files changed, 23 insertions(+), 7 deletions(-) diff --git a/JGE/src/JGfx-fake.cpp b/JGE/src/JGfx-fake.cpp index 917d1f7ab..a90097b2f 100644 --- a/JGE/src/JGfx-fake.cpp +++ b/JGE/src/JGfx-fake.cpp @@ -65,7 +65,7 @@ void JQuad::SetHotSpot(float x, float y) ////////////////////////////////////////////////////////////////////////// -JTexture::JTexture() : mBuffer(NULL) +JTexture::JTexture() : mWidth(0), mHeight(0), mBuffer(NULL) { mTexId = -1; } @@ -305,14 +305,12 @@ void JRenderer::TransferTextureToGLContext(JTexture& inTexture) JTexture* JRenderer::CreateTexture(int width, int height, int mode __attribute__((unused))) { JTexture *tex = new JTexture(); - return tex; } JTexture* JRenderer::LoadTexture(const char* filename, int mode, int textureFormat) { JTexture *tex = new JTexture(); - return tex; } diff --git a/JGE/src/pc/JGfx.cpp b/JGE/src/pc/JGfx.cpp index 6050eeeab..da598a336 100644 --- a/JGE/src/pc/JGfx.cpp +++ b/JGE/src/pc/JGfx.cpp @@ -343,7 +343,7 @@ void JQuad::SetHotSpot(float x, float y) ////////////////////////////////////////////////////////////////////////// -JTexture::JTexture() : mBuffer(NULL) +JTexture::JTexture() : mBuffer(NULL), mHeight(0), mWidth(0) { mTexId = -1; } diff --git a/projects/mtg/include/AllAbilities.h b/projects/mtg/include/AllAbilities.h index 6ff6c7521..2aac5f654 100644 --- a/projects/mtg/include/AllAbilities.h +++ b/projects/mtg/include/AllAbilities.h @@ -1258,6 +1258,7 @@ public: GenericActivatedAbility(GameObserver* observer, string newName,string castRestriction,int _id, MTGCardInstance * card, MTGAbility * a, ManaCost * _cost, string limit = "",MTGAbility * sideEffects = NULL,string usesBeforeSideEffects = "", int restrictions = 0, MTGGameZone * dest = NULL); + GenericActivatedAbility(const GenericActivatedAbility& other); int resolve(); const char * getMenuText(); int isReactingToClick(MTGCardInstance * card, ManaCost * mana = NULL); diff --git a/projects/mtg/src/ActionStack.cpp b/projects/mtg/src/ActionStack.cpp index 6509bc217..140a38ecc 100644 --- a/projects/mtg/src/ActionStack.cpp +++ b/projects/mtg/src/ActionStack.cpp @@ -675,6 +675,7 @@ ActionStack::ActionStack(GameObserver* game) currentState = -1; mode = ACTIONSTACK_STANDARD; checked = 0; + lastActionController = NULL; if(!observer->getResourceManager()) return; for (int i = 0; i < 8; ++i) diff --git a/projects/mtg/src/AllAbilities.cpp b/projects/mtg/src/AllAbilities.cpp index d0f2cad43..028293bdd 100644 --- a/projects/mtg/src/AllAbilities.cpp +++ b/projects/mtg/src/AllAbilities.cpp @@ -55,6 +55,12 @@ GenericActivatedAbility::GenericActivatedAbility(GameObserver* observer, string target = ability->target; } +GenericActivatedAbility::GenericActivatedAbility(const GenericActivatedAbility &other): + ActivatedAbility(other), NestedAbility(other), activeZone(other.activeZone), newName(other.newName) +{ + +} + int GenericActivatedAbility::resolve() { //Note: I've seen a similar block in some other MTGAbility, can this be refactored . @@ -105,6 +111,7 @@ int GenericActivatedAbility::testDestroy() GenericActivatedAbility * GenericActivatedAbility::clone() const { GenericActivatedAbility * a = NEW GenericActivatedAbility(*this); + a->ability = ability->clone(); return a; } diff --git a/projects/mtg/src/CardPrimitive.cpp b/projects/mtg/src/CardPrimitive.cpp index 0af4460d5..fc206f609 100644 --- a/projects/mtg/src/CardPrimitive.cpp +++ b/projects/mtg/src/CardPrimitive.cpp @@ -84,6 +84,9 @@ int CardPrimitive::init() alias = 0; restrictions = NULL; dredgeAmount = 0; + + power = 0; + toughness = 0; return 1; } diff --git a/projects/mtg/src/CardSelector.cpp b/projects/mtg/src/CardSelector.cpp index cae1bee14..ce94a404c 100644 --- a/projects/mtg/src/CardSelector.cpp +++ b/projects/mtg/src/CardSelector.cpp @@ -66,7 +66,7 @@ CardSelector::SelectorMemory::SelectorMemory() } CardSelector::CardSelector(GameObserver *observer, DuelLayers* duel) : - CardSelectorBase(observer), active(NULL), duel(duel), limitor(NULL), bigpos(300, 145, 1.0, 0.0, 220) + CardSelectorBase(observer), active(NULL), duel(duel), limitor(NULL), bigpos(300, 145, 1.0, 0.0, 220), timer(0.0f) { } diff --git a/projects/mtg/src/GameOptions.cpp b/projects/mtg/src/GameOptions.cpp index b82265623..4e60d8d85 100644 --- a/projects/mtg/src/GameOptions.cpp +++ b/projects/mtg/src/GameOptions.cpp @@ -956,7 +956,7 @@ OptionMaxGrade::OptionMaxGrade() // MARK: OptionASkipPhase -OptionASkipPhase OptionASkipPhase::mDef; +OptionASkipPhase OptionASkipPhase::mDef = OptionASkipPhase(); OptionASkipPhase::OptionASkipPhase() { mDef.values.push_back(EnumDefinition::assoc(Constants::ASKIP_NONE, "Off")); diff --git a/projects/mtg/src/MTGAbility.cpp b/projects/mtg/src/MTGAbility.cpp index cebf7e5ac..6ce295848 100644 --- a/projects/mtg/src/MTGAbility.cpp +++ b/projects/mtg/src/MTGAbility.cpp @@ -4368,6 +4368,7 @@ MTGAbility::MTGAbility(GameObserver* observer, int id, MTGCardInstance * card) : aType = MTGAbility::UNKNOWN; mCost = NULL; forceDestroy = 0; + forcedAlive = 0; oneShot = 0; canBeInterrupted = true; } @@ -4381,6 +4382,7 @@ MTGAbility::MTGAbility(GameObserver* observer, int id, MTGCardInstance * _source aType = MTGAbility::UNKNOWN; mCost = NULL; forceDestroy = 0; + forcedAlive = 0; oneShot = 0; canBeInterrupted = true; } @@ -5451,6 +5453,7 @@ AManaProducer::AManaProducer(GameObserver* observer, int id, MTGCardInstance * c aType = MTGAbility::MANA_PRODUCER; setCost(_cost); output = _output; + tap = 0; Producing = producing; menutext = ""; DoesntEmpty = doesntEmpty; diff --git a/projects/mtg/src/MTGCardInstance.cpp b/projects/mtg/src/MTGCardInstance.cpp index a44f1aae2..7baaa63af 100644 --- a/projects/mtg/src/MTGCardInstance.cpp +++ b/projects/mtg/src/MTGCardInstance.cpp @@ -125,6 +125,7 @@ int MTGCardInstance::init() void MTGCardInstance::initMTGCI() { + X = 0; sample = ""; model = NULL; isToken = false; @@ -195,6 +196,8 @@ void MTGCardInstance::initMTGCI() lastController = NULL; regenerateTokens = 0; blocked = false; + graveEffects = false; + exileEffects = false; currentZone = NULL; cardsAbilities = vector(); data = this; //an MTGCardInstance point to itself for data, allows to update it without killing the underlying database item diff --git a/projects/mtg/src/StyleManager.cpp b/projects/mtg/src/StyleManager.cpp index e2005a7c5..e904808aa 100644 --- a/projects/mtg/src/StyleManager.cpp +++ b/projects/mtg/src/StyleManager.cpp @@ -25,7 +25,7 @@ void StyleManager::killRules() styles.clear(); } -StyleManager::StyleManager() +StyleManager::StyleManager(): topRule(0), topSize(0), playerSrc(0) { loadRules(); } From 0db2925e7a5fe2062199b0b4429dd9da04335de5 Mon Sep 17 00:00:00 2001 From: Tobias Loose Date: Fri, 29 Nov 2013 18:44:30 +0100 Subject: [PATCH 2/2] Fix initialization orders --- JGE/src/pc/JGfx.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/JGE/src/pc/JGfx.cpp b/JGE/src/pc/JGfx.cpp index da598a336..ea71b167c 100644 --- a/JGE/src/pc/JGfx.cpp +++ b/JGE/src/pc/JGfx.cpp @@ -343,7 +343,7 @@ void JQuad::SetHotSpot(float x, float y) ////////////////////////////////////////////////////////////////////////// -JTexture::JTexture() : mBuffer(NULL), mHeight(0), mWidth(0) +JTexture::JTexture() : mWidth(0), mHeight(0), mBuffer(NULL) { mTexId = -1; }