From d8d4977e5bd84626a697efe87cca85f8d3cc68ee Mon Sep 17 00:00:00 2001 From: "omegablast2002@yahoo.com" Date: Sun, 19 Dec 2010 21:20:30 +0000 Subject: [PATCH] fixed a rare crash when more then one creature had either treason or unearth in the battlefield at the same turn...they would be put in graveyard and the z->nbcards would change in value, meaning that the incrementer was now able to accidently step out of the vector and hit an invalid pointer. now once it hits the bottom of each pass if the number of cards changed in the field start the cycle over. --- projects/mtg/src/GameObserver.cpp | 35 ++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/projects/mtg/src/GameObserver.cpp b/projects/mtg/src/GameObserver.cpp index c70d5e3fa..7ae697238 100644 --- a/projects/mtg/src/GameObserver.cpp +++ b/projects/mtg/src/GameObserver.cpp @@ -549,20 +549,14 @@ void GameObserver::gameStateBasedEffects() for (int j = 0; j < nbcards; ++j) { MTGCardInstance * c = z->cards[j]; + + if(!c)break; while (c->flanked) {//undoes the flanking on a card c->power += 1; c->addToToughness(1); c->flanked -= 1; } - if (c->has(Constants::TREASON)) - { - WEvent * e = NEW WEventCardSacrifice(c); - GameObserver * game = GameObserver::GetInstance(); - game->receiveEvent(e); - p->game->putInGraveyard(c); - } - if (c->has(Constants::UNEARTH)) p->game->putInExile(c); if (c->fresh) c->fresh = 0; if (c->has(Constants::ONLYONEBOTH)) { @@ -571,6 +565,31 @@ void GameObserver::gameStateBasedEffects() } } + for (int t = 0; t < nbcards; t++) + { + MTGCardInstance * c = z->cards[t]; + + if (c->has(Constants::TREASON)) + { + WEvent * e = NEW WEventCardSacrifice(c); + GameObserver * game = GameObserver::GetInstance(); + game->receiveEvent(e); + + p->game->putInGraveyard(c); + } + if (c->has(Constants::UNEARTH)) + { + p->game->putInExile(c); + + } + if(nbcards > z->nb_cards) + { + t = 0; + nbcards = z->nb_cards; + } + } + + MTGGameZone * f = p->game->graveyard; for (int k = 0; k < f->nb_cards; k++) {