[Orxonox-commit 1336] r6054 - in code/trunk/src: modules/overlays/hud orxonox/overlays

scheusso at orxonox.net scheusso at orxonox.net
Fri Nov 13 11:12:31 CET 2009


Author: scheusso
Date: 2009-11-13 11:12:31 +0100 (Fri, 13 Nov 2009)
New Revision: 6054

Modified:
   code/trunk/src/modules/overlays/hud/HUDHealthBar.cc
   code/trunk/src/modules/overlays/hud/HUDHealthBar.h
   code/trunk/src/modules/overlays/hud/UnderAttackHealthBar.cc
   code/trunk/src/modules/overlays/hud/UnderAttackHealthBar.h
   code/trunk/src/orxonox/overlays/OverlayGroup.cc
   code/trunk/src/orxonox/overlays/OverlayGroup.h
Log:
trying to solve a double free bug (replaced OrxonoxOverlay pointers with smart pointers)


Modified: code/trunk/src/modules/overlays/hud/HUDHealthBar.cc
===================================================================
--- code/trunk/src/modules/overlays/hud/HUDHealthBar.cc	2009-11-13 09:30:18 UTC (rev 6053)
+++ code/trunk/src/modules/overlays/hud/HUDHealthBar.cc	2009-11-13 10:12:31 UTC (rev 6054)
@@ -47,7 +47,7 @@
 
         this->textoverlay_ = new OverlayText(this);
 
-        assert(this->textoverlay_);
+        assert(this->textoverlay_.get());
 
         this->textoverlay_->setCaption("");
     }
@@ -55,7 +55,10 @@
     HUDHealthBar::~HUDHealthBar()
     {
         if (this->isInitialized())
+        {
             this->textoverlay_->destroy();
+            this->textoverlay_ = 0;
+        }
     }
 
     void HUDHealthBar::XMLPort(Element& xmlelement, XMLPort::Mode mode)
@@ -105,7 +108,7 @@
     {
         SUPER(HUDHealthBar, changedOverlayGroup);
 
-        this->getOverlayGroup()->addElement(this->textoverlay_);
+        this->getOverlayGroup()->addElement(this->textoverlay_.get());
     }
 
     void HUDHealthBar::changedVisibility()

Modified: code/trunk/src/modules/overlays/hud/HUDHealthBar.h
===================================================================
--- code/trunk/src/modules/overlays/hud/HUDHealthBar.h	2009-11-13 09:30:18 UTC (rev 6053)
+++ code/trunk/src/modules/overlays/hud/HUDHealthBar.h	2009-11-13 10:12:31 UTC (rev 6054)
@@ -111,7 +111,7 @@
 
         private:
             WeakPtr<Pawn> owner_;
-            OverlayText* textoverlay_;
+            SmartPtr<OverlayText> textoverlay_;
             bool bUseBarColour_;
             ColourValue textColour_;
     };

Modified: code/trunk/src/modules/overlays/hud/UnderAttackHealthBar.cc
===================================================================
--- code/trunk/src/modules/overlays/hud/UnderAttackHealthBar.cc	2009-11-13 09:30:18 UTC (rev 6053)
+++ code/trunk/src/modules/overlays/hud/UnderAttackHealthBar.cc	2009-11-13 10:12:31 UTC (rev 6054)
@@ -33,6 +33,7 @@
 #include "infos/PlayerInfo.h"
 #include "gametypes/UnderAttack.h"
 #include "worldentities/pawns/Destroyer.h"
+#include "overlays/OverlayGroup.h"
 
 namespace orxonox
 {
@@ -57,7 +58,10 @@
     UnderAttackHealthBar::~UnderAttackHealthBar()
     {
         if (this->isInitialized())
+        {
             this->text_->destroy();
+            this->text_ = 0;
+        }
     }
 
     void UnderAttackHealthBar::XMLPort(Element& xmlelement, XMLPort::Mode mode)
@@ -89,6 +93,13 @@
             }
         }
     }
+    
+    void UnderAttackHealthBar::changedOverlayGroup()
+    {
+        SUPER(UnderAttackHealthBar, changedOverlayGroup);
+        
+        this->getOverlayGroup()->addElement(this->text_.get());
+    }
 
     void UnderAttackHealthBar::init()
     {

Modified: code/trunk/src/modules/overlays/hud/UnderAttackHealthBar.h
===================================================================
--- code/trunk/src/modules/overlays/hud/UnderAttackHealthBar.h	2009-11-13 09:30:18 UTC (rev 6053)
+++ code/trunk/src/modules/overlays/hud/UnderAttackHealthBar.h	2009-11-13 10:12:31 UTC (rev 6054)
@@ -45,6 +45,7 @@
 
             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
             virtual void changedOwner();
+            virtual void changedOverlayGroup();
 
             inline void setDescriptionPickPoint(const Vector2& pickpoint)
                 { this->text_->setPickPoint(pickpoint); }
@@ -60,7 +61,7 @@
             void init();
 
             PlayerInfo* owner_;
-            OverlayText* text_;
+            SmartPtr<OverlayText> text_;
             Timer inittimer_;
     };
 }

Modified: code/trunk/src/orxonox/overlays/OverlayGroup.cc
===================================================================
--- code/trunk/src/orxonox/overlays/OverlayGroup.cc	2009-11-13 09:30:18 UTC (rev 6053)
+++ code/trunk/src/orxonox/overlays/OverlayGroup.cc	2009-11-13 10:12:31 UTC (rev 6054)
@@ -59,8 +59,9 @@
 
     OverlayGroup::~OverlayGroup()
     {
-        for (std::set<OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
+        for (std::set< SmartPtr<OrxonoxOverlay> >::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
             (*it)->destroy();
+        this->hudElements_.clear();
     }
 
     /**
@@ -82,7 +83,7 @@
     //! Scales every element in the set.
     void OverlayGroup::setScale(const Vector2& scale)
     {
-        for (std::set<OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
+        for (std::set< SmartPtr<OrxonoxOverlay> >::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
             (*it)->scale(scale / this->scale_);
         this->scale_ = scale;
     }
@@ -90,7 +91,7 @@
     //! Scrolls every element in the set.
     void OverlayGroup::setScroll(const Vector2& scroll)
     {
-        for (std::set<OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
+        for (std::set< SmartPtr<OrxonoxOverlay> >::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
             (*it)->scroll(scroll - this->scroll_);
         this->scroll_ = scroll;
     }
@@ -103,7 +104,7 @@
     */
     void OverlayGroup::addElement(OrxonoxOverlay* element)
     {
-        hudElements_.insert(element);
+        hudElements_.insert(SmartPtr<OrxonoxOverlay>(element));
         element->setOverlayGroup( this );
         if (this->owner_)
             element->setOwner(this->owner_);
@@ -119,7 +120,7 @@
     */
     bool OverlayGroup::removeElement(OrxonoxOverlay* element)
     {
-        if(this->hudElements_.erase(element) == 0)
+        if(this->hudElements_.erase(SmartPtr<OrxonoxOverlay>(element)) == 0)
             return false;
         return true;
     }
@@ -129,10 +130,10 @@
     {
         if (index < this->hudElements_.size())
         {
-            std::set<OrxonoxOverlay*>::const_iterator it = hudElements_.begin();
+            std::set< SmartPtr<OrxonoxOverlay> >::const_iterator it = hudElements_.begin();
             for (unsigned int i = 0; i != index; ++it, ++i)
                 ;
-            return (*it);
+            return it->get();
         }
         else
             return 0;
@@ -143,7 +144,7 @@
     {
         SUPER( OverlayGroup, changedVisibility );
         
-        for (std::set<OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
+        for (std::set< SmartPtr<OrxonoxOverlay> >::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
             (*it)->changedVisibility(); //inform all Child Overlays that our visibility has changed
     }
 
@@ -151,7 +152,7 @@
     {
         this->owner_ = owner;
 
-        for (std::set<OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
+        for (std::set< SmartPtr<OrxonoxOverlay> >::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
             (*it)->setOwner(owner);
     }
 

Modified: code/trunk/src/orxonox/overlays/OverlayGroup.h
===================================================================
--- code/trunk/src/orxonox/overlays/OverlayGroup.h	2009-11-13 09:30:18 UTC (rev 6053)
+++ code/trunk/src/orxonox/overlays/OverlayGroup.h	2009-11-13 10:12:31 UTC (rev 6054)
@@ -63,7 +63,7 @@
         static void scaleGroup(const std::string& name, float scale);
         static void scrollGroup(const std::string& name, const Vector2& scroll);
 
-        inline const std::set<OrxonoxOverlay*>& getOverlays() const
+        inline const std::set< SmartPtr<OrxonoxOverlay> >& getOverlays() const
             { return this->hudElements_; }
 
         void changedVisibility();
@@ -89,7 +89,7 @@
         OrxonoxOverlay* getElement(unsigned int index);
 
     private:
-        std::set<OrxonoxOverlay*> hudElements_;    //!< Contains all the OrxonoxOverlays of the this group.
+        std::set< SmartPtr<OrxonoxOverlay> > hudElements_;    //!< Contains all the OrxonoxOverlays of the this group.
         Vector2 scale_;                            //!< Current scale (independent of the elements).
         Vector2 scroll_;                           //!< Current scrolling offset.
         BaseObject* owner_;                        //!< The owner of this OverlayGroup




More information about the Orxonox-commit mailing list