Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6348 for code/branches


Ignore:
Timestamp:
Dec 14, 2009, 12:50:22 AM (15 years ago)
Author:
rgrieder
Message:

Adding OrxonoxClass::preDestroy(). This method gets called when an object is about to be destroyed. The only way to prevent that is by overriding preDestroy() and then creating a SmartPtr to 'this'. This allows us to delay the destruction of an object, for instance when destroyed by the loader.

Location:
code/branches/presentation2/src/libraries/core
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation2/src/libraries/core/OrxonoxClass.cc

    r6277 r6348  
    7878        this->requestedDestruction_ = true;
    7979        if (this->referenceCount_ == 0)
    80             delete this;
     80        {
     81            this->preDestroy();
     82            if (this->referenceCount_ == 0)
     83                delete this;
     84        }
    8185    }
    8286
  • code/branches/presentation2/src/libraries/core/OrxonoxClass.h

    r6121 r6348  
    135135            {   return const_cast<OrxonoxClass*>(this)->getDerivedPointer<T>(classID);   }
    136136
     137        protected:
     138            virtual void preDestroy() {}
     139
    137140        private:
    138141            /** @brief Increments the reference counter (for smart pointers). */
     
    141144            /** @brief Decrements the reference counter (for smart pointers). */
    142145            inline void decrementReferenceCount()
    143                 { --this->referenceCount_; if (this->referenceCount_ == 0 && this->requestedDestruction_) { delete this; } }
     146            {
     147                --this->referenceCount_;
     148                if (this->referenceCount_ == 0 && this->requestedDestruction_)
     149                    this->destroy();
     150            }
    144151               
    145152            /** @brief Register a weak pointer which points to this object. */
Note: See TracChangeset for help on using the changeset viewer.