Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8667 for code/branches


Ignore:
Timestamp:
May 29, 2011, 6:44:45 PM (13 years ago)
Author:
dafrick
Message:

Possible fix for segfaults due to player being NULL.

Location:
code/branches/presentation/src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation/src/modules/docking/Dock.cc

    r8645 r8667  
    8484    {
    8585        PlayerTrigger* pTrigger = orxonox_cast<PlayerTrigger*>(trigger);
    86         Pawn* pawn = NULL;
     86        PlayerInfo* player = NULL;
    8787
    8888        // Check whether it is a player trigger and extract pawn from it
     
    9393                return false;
    9494            }
    95             pawn = pTrigger->getTriggeringPlayer();
     95            player = pTrigger->getTriggeringPlayer();
    9696        }
    9797        else
     
    100100            return false;
    101101        }
    102         if(pawn == NULL)
    103         {
    104             COUT(4) << "Docking::execute Can't retrieve Pawn from Trigger. (" << trigger->getIdentifier()->getName() << ")" << std::endl;
    105             return false;
    106         }
    107 
    108         // Extract the PlayerInfo from the Pawn.
    109         PlayerInfo* player = pawn->getPlayer();
    110102        if(player == NULL)
    111103        {
    112             COUT(2) << "Docking::execute The PlayerInfo* is NULL." << std::endl;
     104            COUT(4) << "Docking::execute Can't retrieve PlayerInfo from Trigger. (" << trigger->getIdentifier()->getName() << ")" << std::endl;
    113105            return false;
    114106        }
  • code/branches/presentation/src/modules/notifications/NotificationDispatcher.cc

    r8666 r8667  
    140140
    141141        PlayerTrigger* pTrigger = orxonox_cast<PlayerTrigger*>(trigger);
    142         Pawn* pawn = NULL;
     142        PlayerInfo* player = NULL;
    143143
    144144        // If the trigger is a PlayerTrigger.
     
    148148                return false;
    149149            else
    150                 pawn = pTrigger->getTriggeringPlayer();
     150                player = pTrigger->getTriggeringPlayer();
    151151        }
    152152        else
    153153            return false;
    154154
    155         if(pawn == NULL)
     155        if(player == NULL)
    156156        {
    157157            COUT(4) << "The NotificationDispatcher was triggered by an entity other than a Pawn. (" << trigger->getIdentifier()->getName() << ")" << std::endl;
     
    159159        }
    160160
    161         // Extract the PlayerInfo from the Pawn.
    162         PlayerInfo* player = pawn->getPlayer();
    163 
    164         if(player == NULL)
    165         {
    166             CCOUT(3) << "The PlayerInfo* is NULL." << std::endl;
    167             return false;
    168         }
    169 
    170         // HACK fix. Resolve this issue another way...
    171         if(GameMode::isStandalone())
    172             this->dispatch(0);
    173         else
    174             this->dispatch(player->getClientID());
     161        this->dispatch(player->getClientID());
    175162
    176163        return true;
  • code/branches/presentation/src/modules/objects/Script.cc

    r7493 r8667  
    140140
    141141        PlayerTrigger* pTrigger = orxonox_cast<PlayerTrigger*>(trigger);
    142         Pawn* pawn = NULL;
     142        PlayerInfo* player = NULL;
    143143
    144144        // If the trigger is a PlayerTrigger.
     
    148148                return false;
    149149            else
    150                 pawn = pTrigger->getTriggeringPlayer();
     150                player = pTrigger->getTriggeringPlayer();
    151151        }
    152152        else
    153153            return false;
    154154
    155         if(pawn == NULL)  //TODO: Will this ever happen? If not, change in NotificationDispatcher as well.
     155        if(player == NULL)  //TODO: Will this ever happen? If not, change in NotificationDispatcher as well.
    156156        {
    157157            COUT(4) << "The Script was triggered by an entity other than a Pawn. (" << trigger->getIdentifier()->getName() << ")" << std::endl;
    158             return false;
    159         }
    160 
    161         // Extract the PlayerInfo from the Pawn.
    162         PlayerInfo* player = pawn->getPlayer();
    163 
    164         if(player == NULL)
    165         {
    166             COUT(3) << "The PlayerInfo* is NULL." << std::endl;
    167158            return false;
    168159        }
  • code/branches/presentation/src/modules/objects/triggers/DistanceTrigger.cc

    r8637 r8667  
    205205                        entity = entity->getParent();
    206206
    207                     Pawn* player = orxonox_cast<Pawn*>(entity);
    208                     this->setTriggeringPlayer(player);
     207                    Pawn* pawn = orxonox_cast<Pawn*>(entity);
     208                    if(pawn != NULL)
     209                        this->setTriggeringPawn(pawn);
     210                    else
     211                        CCOUT(2) << "Pawn was NULL." << endl;
    209212                }
    210213               
  • code/branches/presentation/src/modules/objects/triggers/MultiTriggerContainer.cc

    r7601 r8667  
    7373        {
    7474            this->setForPlayer(true);
    75             this->setTriggeringPlayer(pawn);
     75            this->setTriggeringPawn(pawn);
    7676        }
    7777    }
  • code/branches/presentation/src/modules/questsystem/QuestEffectBeacon.cc

    r8351 r8667  
    113113
    114114        PlayerTrigger* pTrigger = orxonox_cast<PlayerTrigger*>(trigger);
    115         Pawn* pawn = NULL;
     115        PlayerInfo* player = NULL;
    116116
    117117        // If the trigger is a PlayerTrigger.
     
    121121                return false;
    122122            else
    123                 pawn = pTrigger->getTriggeringPlayer();
     123                player = pTrigger->getTriggeringPlayer();
    124124        }
    125125        else
    126126            return false;
    127127
    128         if(pawn == NULL)
     128        if(player == NULL)
    129129        {
    130130            COUT(4) << "The QuestEffectBeacon was triggered by an entity other than a Pawn. (" << trigger->getIdentifier()->getName() << ")" << std::endl;
    131             return false;
    132         }
    133 
    134         // Extract the PlayerInfo from the Pawn.
    135         PlayerInfo* player = pawn->getPlayer();
    136 
    137         if(player == NULL)
    138         {
    139             COUT(3) << "The PlayerInfo* is NULL." << std::endl;
    140131            return false;
    141132        }
  • code/branches/presentation/src/orxonox/interfaces/InterfaceCompilation.cc

    r8637 r8667  
    5959        RegisterRootObject(PlayerTrigger);
    6060
    61         this->player_ = NULL;
    6261        this->isForPlayer_ = false;
    6362    }
  • code/branches/presentation/src/orxonox/interfaces/PlayerTrigger.h

    r7601 r8667  
    4040#include "core/OrxonoxClass.h"
    4141
     42#include "infos/PlayerInfo.h"
     43#include "worldentities/pawns/Pawn.h"
     44
    4245namespace orxonox
    4346{
    4447    /**
    4548    @brief
    46         PlayerTrigger is an interface if implemented by a specific trigger can be used to recover the Player (or more precisely the @ref orxonox::Pawn "Pawn") that triggered it.
     49        PlayerTrigger is an interface if implemented by a specific trigger can be used to recover the Player (or the @ref orxonox::Pawn "Pawn") that triggered it.
    4750
    4851    @author
     
    5861
    5962        /**
    60         @brief Returns the player that triggered the PlayerTrigger.
     63        @brief Returns the Pawn that triggered the PlayerTrigger.
    6164        @return Returns a pointer to the Pawn that triggered the PlayerTrigger.
    6265        */
    63         inline Pawn* getTriggeringPlayer(void) const
     66        inline Pawn* getTriggeringPawn(void) const
     67            { return this->pawn_.get(); }
     68
     69        /**
     70        @brief Returns the player that triggered the PlayerTrigger.
     71        @return Returns a pointer to the PlayerInfo that triggered the PlayerTrigger.
     72        */
     73        inline PlayerInfo* getTriggeringPlayer(void) const
    6474            { return this->player_; }
    6575
    6676        /**
    67         @brief Checks whether the PlayerTrigger normally returns a Pawn.
    68         @return Returns true if the PlayerTrigger normally returns a Pawn.
     77        @brief Checks whether the PlayerTrigger normally returns a Pawn/PlayerInfo.
     78        @return Returns true if the PlayerTrigger normally returns a Pawn/PlayerInfo.
    6979        */
    7080        inline bool isForPlayer(void) const
     
    7686        @param player A pointer to the Pawn that triggered the PlayerTrigger.
    7787        */
    78         inline void setTriggeringPlayer(Pawn* player)
    79            { this->player_ = player; }
     88        inline void setTriggeringPawn(Pawn* pawn)
     89           { assert(pawn); this->player_ = WeakPtr<PlayerInfo>(pawn->getPlayer()); this->pawn_ = WeakPtr<Pawn>(pawn); }
    8090
    8191        /**
     
    8797
    8898    private:
    89         Pawn* player_; //!< The player that triggered the PlayerTrigger.
     99        WeakPtr<PlayerInfo> player_; //!< The player that triggered the PlayerTrigger.
     100        WeakPtr<Pawn> pawn_; //!< The Pawn that triggered the PlayerTrigger.
    90101        bool isForPlayer_; //!< Is true when the PlayerTrigger should be set to normally be triggered by Pawns.
    91102
Note: See TracChangeset for help on using the changeset viewer.