Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6725


Ignore:
Timestamp:
Apr 13, 2010, 10:39:54 PM (14 years ago)
Author:
dafrick
Message:

Resolved bug, that caused orxonox to crash whenever a level with pickups was loaded twice in one session.
Also some more debug/info output, commenting and cleanup.

Location:
code/trunk/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/modules/pickup/PickupManager.cc

    r6711 r6725  
    5151    DeclareToluaInterface(Pickup);
    5252   
    53     ManageScopedSingleton(PickupManager, ScopeID::Root, false);
     53    ManageScopedSingleton(PickupManager, ScopeID::Graphics, false);
    5454   
    5555    /*static*/ const std::string PickupManager::guiName_s = "PickupInventory";
     
    6464       
    6565        this->defaultRepresentation_ = new PickupRepresentation();
     66       
     67        COUT(3) << "PickupManager created." << std::endl;
    6668    }
    6769   
     
    7577        if(this->defaultRepresentation_ != NULL)
    7678            this->defaultRepresentation_->destroy();
     79       
     80        this->representations_.clear();
     81       
     82        COUT(3) << "PickupManager destroyed." << std::endl;
    7783    }
    7884   
     
    8995    */
    9096    bool PickupManager::registerRepresentation(const PickupIdentifier* identifier, PickupRepresentation* representation)
    91     {
    92         if(this->representations_.find(identifier) != this->representations_.end()) //!< If the Pickupable already has a RepresentationRegistered.
     97    {       
     98        if(identifier == NULL || representation == NULL || this->representations_.find(identifier) != this->representations_.end()) //!< If the Pickupable already has a Representation registered.
    9399            return false;
    94100       
     
    96102       
    97103        COUT(4) << "PickupRepresentation " << representation << " registered with the PickupManager." << std::endl;
     104        return true;
     105    }
     106   
     107    /**
     108    @brief
     109        Unegisters a PickupRepresentation together with the PickupIdentifier of the Pickupable the PickupRepresentation represents.
     110    @param identifier
     111        The PickupIdentifier identifying the Pickupable.
     112    @param representation
     113        A pointer to the PickupRepresentation.
     114    @return
     115        Returns true if successful and false if not.
     116    */
     117    bool PickupManager::unregisterRepresentation(const PickupIdentifier* identifier, PickupRepresentation* representation)
     118    {       
     119        if(identifier == NULL || representation == NULL)
     120            return false;
     121       
     122        std::map<const PickupIdentifier*, PickupRepresentation*, PickupIdentifierCompare>::iterator it = this->representations_.find(identifier);
     123        if(it == this->representations_.end()) //!< If the Pickupable is not registered in the first place.
     124            return false;
     125       
     126        this->representations_.erase(it);
     127       
     128        COUT(4) << "PickupRepresentation " << representation << " unregistered with the PickupManager." << std::endl;
    98129        return true;
    99130    }
  • code/trunk/src/modules/pickup/PickupManager.h

    r6711 r6725  
    6767           
    6868            bool registerRepresentation(const PickupIdentifier* identifier, PickupRepresentation* representation); //!< Registers a PickupRepresentation together with the PickupIdentifier of the Pickupable the PickupRepresentation represents.
     69            bool unregisterRepresentation(const PickupIdentifier* identifier, PickupRepresentation* representation); //!< Unegisters a PickupRepresentation together with the PickupIdentifier of the Pickupable the PickupRepresentation represents.
    6970            PickupRepresentation* getRepresentation(const PickupIdentifier* identifier); //!< Get the PickupRepresentation representing the Pickupable with the input PickupIdentifier.
    7071           
  • code/trunk/src/modules/pickup/PickupRepresentation.cc

    r6711 r6725  
    4949        This is primarily for use of the PickupManager in creating a default PickupRepresentation.
    5050    */
    51     PickupRepresentation::PickupRepresentation() : BaseObject(NULL), spawnerRepresentation_(NULL)
     51    PickupRepresentation::PickupRepresentation() : BaseObject(NULL), spawnerRepresentation_(NULL), pickup_(NULL)
    5252    {
    5353        RegisterObject(PickupRepresentation);
     
    6060        Default Constructor. Registers the object and initializes its member variables.
    6161    */
    62     PickupRepresentation::PickupRepresentation(BaseObject* creator) : BaseObject(creator), spawnerRepresentation_(NULL)
     62    PickupRepresentation::PickupRepresentation(BaseObject* creator) : BaseObject(creator), spawnerRepresentation_(NULL), pickup_(NULL)
    6363    {
    6464        RegisterObject(PickupRepresentation);
     
    7575        if(this->spawnerRepresentation_ != NULL)
    7676            this->spawnerRepresentation_->destroy();
     77       
     78        if(this->pickup_ != NULL)
     79            PickupManager::getInstance().unregisterRepresentation(this->pickup_->getPickupIdentifier(), this);
    7780    }
    7881   
     
    8790        this->spawnerTemplate_ = "";
    8891        this->inventoryRepresentation_ = "Default";
    89         this->pickup_ = NULL;
    9092    }
    9193   
  • code/trunk/src/orxonox/interfaces/Pickupable.cc

    r6540 r6725  
    4646        Constructor. Registers the objects and initializes its member variables.
    4747    */
    48     Pickupable::Pickupable() : used_(false), pickedUp_(false)
     48    Pickupable::Pickupable() : pickupIdentifier_(NULL), used_(false), pickedUp_(false)
    4949    {       
    5050        RegisterRootObject(Pickupable);
     
    6969            this->setCarrier(NULL);
    7070        }
     71       
     72        if(this->pickupIdentifier_ != NULL)
     73            this->pickupIdentifier_->destroy();
    7174    }
    7275   
  • code/trunk/src/orxonox/pickup/PickupIdentifier.cc

    r6540 r6725  
    4848        RegisterRootObject(PickupIdentifier);
    4949       
     50        if(pickup == NULL)
     51            COUT(1) << "Error, PickupIdentifier was created without a valid Pickupable." << std::endl;
     52       
    5053        this->pickup_ = pickup;
    5154    }
     
    5356    PickupIdentifier::~PickupIdentifier()
    5457    {
    55        
     58
    5659    }
    5760   
     
    6669    int PickupIdentifier::compare(const PickupIdentifier* identifier) const
    6770    {
     71        if(identifier == NULL)
     72        {
     73            return 1;
     74            COUT(1) << "Error in PickupIdentifier::compare: Input Identifier is NULL." << std::endl;
     75        }
     76       
     77        if(identifier->pickup_ == NULL && this->pickup_ == NULL)
     78        {
     79            return 0;
     80            COUT(1) << "Error in PickupIdentifier::compare: Pickup stored by Identifier is NULL." << std::endl;
     81        }
     82       
     83        if(identifier->pickup_ == NULL)
     84        {
     85            return 1;
     86            COUT(1) << "Error in PickupIdentifier::compare: Pickup stored by Identifier is NULL." << std::endl;
     87        }
     88       
     89        if(this->pickup_ == NULL)
     90        {
     91            return -1;
     92            COUT(1) << "Error in PickupIdentifier::compare: Pickup stored by Identifier is NULL." << std::endl;
     93        }
     94       
    6895        //! If the classIdentifiers are not the same (meaning the PickupIdentifiers identify different classes), the obviously the two Pickupables identified by the PickupIdentifiers cannot be the same. An ordering is established through the alphabetical ordering of the respective classnames.
    6996        if(!identifier->pickup_->getIdentifier()->isExactlyA(this->pickup_->getIdentifier()))
     
    91118        }
    92119           
    93         return false;
     120        return 0;
    94121    }
    95122   
Note: See TracChangeset for help on using the changeset viewer.