Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7885


Ignore:
Timestamp:
Feb 14, 2011, 3:27:56 PM (13 years ago)
Author:
landauf
Message:

fixed minor memory leak

Location:
code/trunk/src/modules/pong
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/modules/pong/PongBall.cc

    r7852 r7885  
    4848        this->accelerationFactor_ = 1.0f;
    4949        this->bat_ = 0;
     50        this->bDeleteBats_ = false;
    5051        this->batID_ = new unsigned int[2];
    5152        this->batID_[0] = OBJECTID_UNKNOWN;
     
    5859    PongBall::~PongBall()
    5960    {
     61        if (this->isInitialized())
     62        {
     63            if (this->bDeleteBats_)
     64                delete[] this->bat_;
     65
     66            delete[] this->batID_;
     67        }
    6068    }
    6169
     
    167175    void PongBall::setBats(WeakPtr<PongBat>* bats)
    168176    {
     177        if (this->bDeleteBats_)
     178        {
     179            delete[] this->bat_;
     180            this->bDeleteBats_ = false;
     181        }
     182
    169183        this->bat_ = bats;
    170184        this->batID_[0] = this->bat_[0]->getObjectID();
     
    175189    {
    176190        if (!this->bat_)
    177             this->bat_ = new WeakPtr<PongBat>[2]; // TODO: delete this somewhere
     191        {
     192            if (this->bDeleteBats_)
     193                delete[] this->bat_;
     194            else
     195                this->bDeleteBats_ = true;
     196
     197            this->bat_ = new WeakPtr<PongBat>[2];
     198        }
     199
    178200        if (this->batID_[0] != OBJECTID_UNKNOWN)
    179201            this->bat_[0] = orxonox_cast<PongBat*>(Synchronisable::getSynchronisable(this->batID_[0]));
  • code/trunk/src/modules/pong/PongBall.h

    r7852 r7885  
    8080            float batlength_;
    8181            WeakPtr<PongBat>* bat_;
     82            bool bDeleteBats_;
    8283            unsigned int* batID_;
    8384            float relMercyOffset_;
Note: See TracChangeset for help on using the changeset viewer.