Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 11032


Ignore:
Timestamp:
Jan 4, 2016, 12:07:42 AM (8 years ago)
Author:
landauf
Message:

fixed another situation where a timer may keep existing after the level was unloaded.
there is, however, yet another bug in this piece of code (marked with a TODO): a spaceship can be destroyed before the timer is executed which leads to a crash.

Location:
code/branches/presentationHS15/src/orxonox/gametypes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentationHS15/src/orxonox/gametypes/Dynamicmatch.cc

    r10624 r11032  
    8686    }
    8787
     88    Dynamicmatch::~Dynamicmatch()
     89    {
     90        for (std::set<Timer*>::iterator it = this->piggyTimers_.begin(); it != this->piggyTimers_.end(); ++it)
     91            delete (*it);
     92    }
     93
    8894    void Dynamicmatch::setConfigValues()
    8995    {
     
    312318            spaceship->addSpeedFactor(5);
    313319            ExecutorPtr executor = createExecutor(createFunctor(&Dynamicmatch::resetSpeedFactor, this));
    314             executor->setDefaultValue(0, spaceship);
    315             new Timer(10, false, executor, true);
     320            Timer* timer = new Timer(10, false, executor);
     321            executor->setDefaultValue(0, spaceship); // TODO: use WeakPtr because spaceship can be destroyed in the meantime
     322            executor->setDefaultValue(1, timer);
     323            this->piggyTimers_.insert(timer);
    316324        }
    317325    }
     
    590598    }
    591599
    592     void Dynamicmatch::resetSpeedFactor(SpaceShip* spaceship)// helper function
     600    void Dynamicmatch::resetSpeedFactor(SpaceShip* spaceship, Timer* timer)// helper function
    593601    {
    594602        if (spaceship)
     
    596604            spaceship->addSpeedFactor(1.0f/5.0f);
    597605        }
     606
     607        this->piggyTimers_.erase(timer);
     608        delete timer;
    598609    }
    599610
  • code/branches/presentationHS15/src/orxonox/gametypes/Dynamicmatch.h

    r10624 r11032  
    3333
    3434#include <map>
     35#include <set>
    3536#include <vector>
    3637
     
    4546        public:
    4647            Dynamicmatch(Context* context);
    47             virtual ~Dynamicmatch() {}
     48            virtual ~Dynamicmatch();
    4849
    4950            bool notEnoughPigs;
     
    7778            virtual void rewardPig();
    7879            void grantPigBoost(SpaceShip* spaceship); // Grant the piggy a boost.
    79             void resetSpeedFactor(SpaceShip* spaceship);
     80            void resetSpeedFactor(SpaceShip* spaceship, Timer* timer);
    8081            void tick (float dt);// used to end the game
    8182            SpawnPoint* getBestSpawnPoint(PlayerInfo* player) const;
     
    8889            std::map< PlayerInfo*, int > playerParty_; //player's parties are recorded here
    8990            std::vector<ColourValue> partyColours_; //aus TeamDeathmatch
     91            std::set<Timer*> piggyTimers_;
    9092            unsigned int numberOf[3]; //array to count number of chasers, pigs, killers
    9193            float pointsPerTime;
Note: See TracChangeset for help on using the changeset viewer.