Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10553


Ignore:
Timestamp:
Aug 28, 2015, 10:35:51 PM (9 years ago)
Author:
landauf
Message:

fixed reference counting in unload() - unsigned int cannot be < 0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core7/src/libraries/core/module/Plugin.cc

    r10552 r10553  
    5252    void Plugin::load()
    5353    {
    54         if (this->referenceCounter_ == 0)
     54        this->referenceCounter_++;
     55        if (this->referenceCounter_ == 1) // increased from 0 to 1 -> load plugin
    5556        {
    5657            orxout(internal_info) << "Loading plugin " << this->name_ << "..." << endl;
     
    5960        }
    6061        else
    61         {
    62             orxout(internal_info) << "Plugin " << this->name_ << " is already referenced" << endl;
    63         }
    64 
    65         this->referenceCounter_++;
     62            orxout(internal_info) << "Increased reference count for plugin " << this->name_ << " to " << this->referenceCounter_ << endl;
    6663    }
    6764
    6865    void Plugin::unload()
    6966    {
     67        if (this->referenceCounter_ == 0)
     68        {
     69            orxout(internal_warning) << "Tried to dereference plugin " << this->name_ << " more often than it was referenced" << endl;
     70            return;
     71        }
     72
    7073        this->referenceCounter_--;
    71         if (this->referenceCounter_ == 0)
     74        if (this->referenceCounter_ == 0) // reduced from 1 to 0 -> load plugin
    7275        {
    7376            orxout(internal_info) << "Unloading plugin " << this->name_ << "..." << endl;
     
    7679            this->moduleInstance_ = NULL;
    7780        }
    78         else if (this->referenceCounter_ > 0)
    79         {
    80             orxout(internal_info) << "Plugin " << this->name_ << " is still referenced" << endl;
    81         }
    8281        else
    83         {
    84             orxout(internal_warning) << "Plugin " << this->name_ << " was dereferenced more often than it was reference" << endl;
    85             this->referenceCounter_ = 0;
    86         }
     82            orxout(internal_info) << "Reduced reference count for plugin " << this->name_ << " to " << this->referenceCounter_ << endl;
    8783    }
    8884}
Note: See TracChangeset for help on using the changeset viewer.