Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9328


Ignore:
Timestamp:
Jul 22, 2012, 5:57:54 PM (12 years ago)
Author:
landauf
Message:

fixed two possible crashes

Location:
code/branches/presentation2012merge/src/modules/tetris
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation2012merge/src/modules/tetris/Tetris.cc

    r9326 r9328  
    6767        RegisterObject(Tetris);
    6868
    69         this->activeBrick_ = NULL;
     69        this->activeBrick_ = 0;
    7070
    7171        // Pre-set the timer, but don't start it yet.
     
    7676        this->endGameCriteria_ = 0.0f;
    7777        this->setHUDTemplate("TetrisHUD");
    78         this->futureBrick_ = NULL;
     78        this->futureBrick_ = 0;
    7979    }
    8080
     
    9595    void Tetris::cleanup()
    9696    {
    97         if (this->isInitialized())
    98         {
    99             if (this->activeBrick_)
    100             {
    101                 this->activeBrick_->destroy();
    102                 this->activeBrick_ = NULL;
    103             }
    104             if (this->futureBrick_)
    105             {
    106                 this->futureBrick_->destroy();
    107                 this->futureBrick_ = NULL;
    108             }
    109 
    110             for (std::list<TetrisStone*>::iterator it = this->stones_.begin(); it != this->stones_.end(); ++it)
    111                 (*it)->destroy();
    112             this->stones_.clear();
    113         }
     97        if (this->activeBrick_)
     98        {
     99            this->activeBrick_->destroy();
     100            this->activeBrick_ = 0;
     101        }
     102        if (this->futureBrick_)
     103        {
     104            this->futureBrick_->destroy();
     105            this->futureBrick_ = 0;
     106        }
     107
     108        for (std::list<SmartPtr<TetrisStone> >::iterator it = this->stones_.begin(); it != this->stones_.end(); ++it)
     109            (*it)->destroy();
     110        this->stones_.clear();
    114111    }
    115112
     
    129126                this->findFullRows();
    130127                if(this->endGameCriteria_ < 0.1f) //end game if two bricks are created within a 0.1s interval.
    131                 {
    132128                    this->end();
    133                     return;
    134                 }
    135                 this->startBrick();
     129                else
     130                    this->startBrick();
    136131                this->endGameCriteria_ = 0.0f;
    137132            }
     
    148143            return false;
    149144
    150         for(std::list<TetrisStone*>::const_iterator it = this->stones_.begin(); it != this->stones_.end(); ++it)
     145        for(std::list<SmartPtr<TetrisStone> >::const_iterator it = this->stones_.begin(); it != this->stones_.end(); ++it)
    151146        {
    152147            const Vector3& currentStonePosition = (*it)->getPosition(); //!< Saves the position of the currentStone
     
    201196
    202197        // we use a reverse iterator because we have to check for collisions with the topmost stones first
    203         for(std::list<TetrisStone*>::const_reverse_iterator it = this->stones_.rbegin(); it != this->stones_.rend(); ++it)
     198        for(std::list<SmartPtr<TetrisStone> >::const_reverse_iterator it = this->stones_.rbegin(); it != this->stones_.rend(); ++it)
    204199        {
    205200            //Vector3 currentStonePosition = rotateVector((*it)->getPosition(), this->activeBrick_->getRotationCount());
     
    364359        // Make the last brick to be created the active brick.
    365360        this->activeBrick_ = this->futureBrick_;
    366         this->futureBrick_ = NULL;
     361        this->futureBrick_ = 0;
    367362
    368363        // set its position
     
    432427        {
    433428            stonesPerRow = 0;
    434             for(std::list<TetrisStone*>::iterator it = this->stones_.begin(); it != this->stones_.end(); )
    435             {
    436                 std::list<TetrisStone*>::iterator it_temp = it++;
     429            for(std::list<SmartPtr<TetrisStone> >::iterator it = this->stones_.begin(); it != this->stones_.end(); )
     430            {
     431                std::list<SmartPtr<TetrisStone> >::iterator it_temp = it++;
    437432                correctPosition = static_cast<unsigned int>(((*it_temp)->getPosition().y - 5)/this->center_->getStoneSize());
    438433                if(correctPosition == row)
     
    454449    void Tetris::clearRow(unsigned int row)
    455450    {// clear the full row
    456         for(std::list<TetrisStone*>::iterator it = this->stones_.begin(); it != this->stones_.end(); )
     451        for(std::list<SmartPtr<TetrisStone> >::iterator it = this->stones_.begin(); it != this->stones_.end(); )
    457452        {
    458453            if(static_cast<unsigned int>(((*it)->getPosition().y - 5)/this->center_->getStoneSize()) == row)
     
    465460        }
    466461      // adjust height of stones above the deleted row //TODO: check if this could be a source of a bug.
    467         for(std::list<TetrisStone*>::iterator it = this->stones_.begin(); it != this->stones_.end(); ++it)
     462        for(std::list<SmartPtr<TetrisStone> >::iterator it = this->stones_.begin(); it != this->stones_.end(); ++it)
    468463        {
    469464            if(static_cast<unsigned int>(((*it)->getPosition().y - 5)/this->center_->getStoneSize()) > row)
  • code/branches/presentation2012merge/src/modules/tetris/Tetris.h

    r9326 r9328  
    9292
    9393            WeakPtr<TetrisCenterpoint> center_; //!< The playing field.
    94             std::list<TetrisStone*> stones_; //!< A list of all stones in play.
    95             TetrisBrick* activeBrick_;
    96             TetrisBrick* futureBrick_;
     94            std::list<SmartPtr<TetrisStone> > stones_; //!< A list of all stones in play.
     95            WeakPtr<TetrisBrick> activeBrick_;
     96            WeakPtr<TetrisBrick> futureBrick_;
    9797
    9898            Timer starttimer_; //!< A timer to delay the start of the game.
  • code/branches/presentation2012merge/src/modules/tetris/TetrisBrick.cc

    r9327 r9328  
    236236    {
    237237        assert(this->tetris_);
    238         for(unsigned int i = 0; i < brickStones_.size(); i++)
     238        for(unsigned int i = 0; i < this->brickStones_.size(); i++)
    239239        {
    240240            this->brickStones_[i]->detachFromParent();
     
    242242            this->brickStones_[i]->setPosition(this->getPosition()+this->tetris_->rotateVector(this->brickStones_[i]->getPosition(),this->rotationCount_ ));
    243243        }
    244 
     244        this->brickStones_.clear();
    245245    }
    246246
Note: See TracChangeset for help on using the changeset viewer.