Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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.

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.