Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 13, 2009, 11:12:31 AM (15 years ago)
Author:
scheusso
Message:

trying to solve a double free bug (replaced OrxonoxOverlay pointers with smart pointers)

Location:
code/trunk/src/orxonox/overlays
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/orxonox/overlays/OverlayGroup.cc

    r5980 r6054  
    6060    OverlayGroup::~OverlayGroup()
    6161    {
    62         for (std::set<OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
     62        for (std::set< SmartPtr<OrxonoxOverlay> >::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
    6363            (*it)->destroy();
     64        this->hudElements_.clear();
    6465    }
    6566
     
    8384    void OverlayGroup::setScale(const Vector2& scale)
    8485    {
    85         for (std::set<OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
     86        for (std::set< SmartPtr<OrxonoxOverlay> >::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
    8687            (*it)->scale(scale / this->scale_);
    8788        this->scale_ = scale;
     
    9192    void OverlayGroup::setScroll(const Vector2& scroll)
    9293    {
    93         for (std::set<OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
     94        for (std::set< SmartPtr<OrxonoxOverlay> >::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
    9495            (*it)->scroll(scroll - this->scroll_);
    9596        this->scroll_ = scroll;
     
    104105    void OverlayGroup::addElement(OrxonoxOverlay* element)
    105106    {
    106         hudElements_.insert(element);
     107        hudElements_.insert(SmartPtr<OrxonoxOverlay>(element));
    107108        element->setOverlayGroup( this );
    108109        if (this->owner_)
     
    120121    bool OverlayGroup::removeElement(OrxonoxOverlay* element)
    121122    {
    122         if(this->hudElements_.erase(element) == 0)
     123        if(this->hudElements_.erase(SmartPtr<OrxonoxOverlay>(element)) == 0)
    123124            return false;
    124125        return true;
     
    130131        if (index < this->hudElements_.size())
    131132        {
    132             std::set<OrxonoxOverlay*>::const_iterator it = hudElements_.begin();
     133            std::set< SmartPtr<OrxonoxOverlay> >::const_iterator it = hudElements_.begin();
    133134            for (unsigned int i = 0; i != index; ++it, ++i)
    134135                ;
    135             return (*it);
     136            return it->get();
    136137        }
    137138        else
     
    144145        SUPER( OverlayGroup, changedVisibility );
    145146       
    146         for (std::set<OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
     147        for (std::set< SmartPtr<OrxonoxOverlay> >::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
    147148            (*it)->changedVisibility(); //inform all Child Overlays that our visibility has changed
    148149    }
     
    152153        this->owner_ = owner;
    153154
    154         for (std::set<OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
     155        for (std::set< SmartPtr<OrxonoxOverlay> >::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
    155156            (*it)->setOwner(owner);
    156157    }
  • code/trunk/src/orxonox/overlays/OverlayGroup.h

    r5781 r6054  
    6464        static void scrollGroup(const std::string& name, const Vector2& scroll);
    6565
    66         inline const std::set<OrxonoxOverlay*>& getOverlays() const
     66        inline const std::set< SmartPtr<OrxonoxOverlay> >& getOverlays() const
    6767            { return this->hudElements_; }
    6868
     
    9090
    9191    private:
    92         std::set<OrxonoxOverlay*> hudElements_;    //!< Contains all the OrxonoxOverlays of the this group.
     92        std::set< SmartPtr<OrxonoxOverlay> > hudElements_;    //!< Contains all the OrxonoxOverlays of the this group.
    9393        Vector2 scale_;                            //!< Current scale (independent of the elements).
    9494        Vector2 scroll_;                           //!< Current scrolling offset.
Note: See TracChangeset for help on using the changeset viewer.