[Orxonox-commit 3993] r8667 - in code/branches/presentation/src: modules/docking modules/notifications modules/objects modules/objects/triggers modules/questsystem orxonox/interfaces

dafrick at orxonox.net dafrick at orxonox.net
Sun May 29 18:44:45 CEST 2011


Author: dafrick
Date: 2011-05-29 18:44:45 +0200 (Sun, 29 May 2011)
New Revision: 8667

Modified:
   code/branches/presentation/src/modules/docking/Dock.cc
   code/branches/presentation/src/modules/notifications/NotificationDispatcher.cc
   code/branches/presentation/src/modules/objects/Script.cc
   code/branches/presentation/src/modules/objects/triggers/DistanceTrigger.cc
   code/branches/presentation/src/modules/objects/triggers/MultiTriggerContainer.cc
   code/branches/presentation/src/modules/questsystem/QuestEffectBeacon.cc
   code/branches/presentation/src/orxonox/interfaces/InterfaceCompilation.cc
   code/branches/presentation/src/orxonox/interfaces/PlayerTrigger.h
Log:
Possible fix for segfaults due to player being NULL.


Modified: code/branches/presentation/src/modules/docking/Dock.cc
===================================================================
--- code/branches/presentation/src/modules/docking/Dock.cc	2011-05-29 15:46:39 UTC (rev 8666)
+++ code/branches/presentation/src/modules/docking/Dock.cc	2011-05-29 16:44:45 UTC (rev 8667)
@@ -83,7 +83,7 @@
     bool Dock::execute(bool bTriggered, BaseObject* trigger)
     {
         PlayerTrigger* pTrigger = orxonox_cast<PlayerTrigger*>(trigger);
-        Pawn* pawn = NULL;
+        PlayerInfo* player = NULL;
 
         // Check whether it is a player trigger and extract pawn from it
         if(pTrigger != NULL)
@@ -92,24 +92,16 @@
                 COUT(4) << "Docking:execute PlayerTrigger was not triggered by a player.." << std::endl;
                 return false;
             }
-            pawn = pTrigger->getTriggeringPlayer();
+            player = pTrigger->getTriggeringPlayer();
         }
         else
         {
             COUT(4) << "Docking::execute Not a player trigger, can't extract pawn from it.." << std::endl;
             return false;
         }
-        if(pawn == NULL)
-        {
-            COUT(4) << "Docking::execute Can't retrieve Pawn from Trigger. (" << trigger->getIdentifier()->getName() << ")" << std::endl;
-            return false;
-        }
-
-        // Extract the PlayerInfo from the Pawn.
-        PlayerInfo* player = pawn->getPlayer();
         if(player == NULL)
         {
-            COUT(2) << "Docking::execute The PlayerInfo* is NULL." << std::endl;
+            COUT(4) << "Docking::execute Can't retrieve PlayerInfo from Trigger. (" << trigger->getIdentifier()->getName() << ")" << std::endl;
             return false;
         }
 

Modified: code/branches/presentation/src/modules/notifications/NotificationDispatcher.cc
===================================================================
--- code/branches/presentation/src/modules/notifications/NotificationDispatcher.cc	2011-05-29 15:46:39 UTC (rev 8666)
+++ code/branches/presentation/src/modules/notifications/NotificationDispatcher.cc	2011-05-29 16:44:45 UTC (rev 8667)
@@ -139,7 +139,7 @@
         COUT(4) << "NotificationDispatcher (&" << this << ") triggered." << std::endl;
 
         PlayerTrigger* pTrigger = orxonox_cast<PlayerTrigger*>(trigger);
-        Pawn* pawn = NULL;
+        PlayerInfo* player = NULL;
 
         // If the trigger is a PlayerTrigger.
         if(pTrigger != NULL)
@@ -147,32 +147,19 @@
             if(!pTrigger->isForPlayer())  // The PlayerTrigger is not exclusively for Pawns which means we cannot extract one.
                 return false;
             else
-                pawn = pTrigger->getTriggeringPlayer();
+                player = pTrigger->getTriggeringPlayer();
         }
         else
             return false;
 
-        if(pawn == NULL)
+        if(player == NULL)
         {
             COUT(4) << "The NotificationDispatcher was triggered by an entity other than a Pawn. (" << trigger->getIdentifier()->getName() << ")" << std::endl;
             return false;
         }
 
-        // Extract the PlayerInfo from the Pawn.
-        PlayerInfo* player = pawn->getPlayer();
+        this->dispatch(player->getClientID());
 
-        if(player == NULL)
-        {
-            CCOUT(3) << "The PlayerInfo* is NULL." << std::endl;
-            return false;
-        }
-
-        // HACK fix. Resolve this issue another way...
-        if(GameMode::isStandalone())
-            this->dispatch(0);
-        else
-            this->dispatch(player->getClientID());
-
         return true;
     }
 

Modified: code/branches/presentation/src/modules/objects/Script.cc
===================================================================
--- code/branches/presentation/src/modules/objects/Script.cc	2011-05-29 15:46:39 UTC (rev 8666)
+++ code/branches/presentation/src/modules/objects/Script.cc	2011-05-29 16:44:45 UTC (rev 8667)
@@ -139,7 +139,7 @@
         COUT(4) << "Script (&" << this << ") triggered." << std::endl;
 
         PlayerTrigger* pTrigger = orxonox_cast<PlayerTrigger*>(trigger);
-        Pawn* pawn = NULL;
+        PlayerInfo* player = NULL;
 
         // If the trigger is a PlayerTrigger.
         if(pTrigger != NULL)
@@ -147,26 +147,17 @@
             if(!pTrigger->isForPlayer())  // The PlayerTrigger is not exclusively for Pawns which means we cannot extract one.
                 return false;
             else
-                pawn = pTrigger->getTriggeringPlayer();
+                player = pTrigger->getTriggeringPlayer();
         }
         else
             return false;
 
-        if(pawn == NULL)  //TODO: Will this ever happen? If not, change in NotificationDispatcher as well.
+        if(player == NULL)  //TODO: Will this ever happen? If not, change in NotificationDispatcher as well.
         {
             COUT(4) << "The Script was triggered by an entity other than a Pawn. (" << trigger->getIdentifier()->getName() << ")" << std::endl;
             return false;
         }
 
-        // Extract the PlayerInfo from the Pawn.
-        PlayerInfo* player = pawn->getPlayer();
-
-        if(player == NULL)
-        {
-            COUT(3) << "The PlayerInfo* is NULL." << std::endl;
-            return false;
-        }
-
         this->execute(player->getClientID());
         return true;
     }

Modified: code/branches/presentation/src/modules/objects/triggers/DistanceTrigger.cc
===================================================================
--- code/branches/presentation/src/modules/objects/triggers/DistanceTrigger.cc	2011-05-29 15:46:39 UTC (rev 8666)
+++ code/branches/presentation/src/modules/objects/triggers/DistanceTrigger.cc	2011-05-29 16:44:45 UTC (rev 8667)
@@ -204,8 +204,11 @@
                     if(this->beaconMode_ == distanceTriggerBeaconMode::identify)
                         entity = entity->getParent();
 
-                    Pawn* player = orxonox_cast<Pawn*>(entity);
-                    this->setTriggeringPlayer(player);
+                    Pawn* pawn = orxonox_cast<Pawn*>(entity);
+                    if(pawn != NULL)
+                        this->setTriggeringPawn(pawn);
+                    else
+                        CCOUT(2) << "Pawn was NULL." << endl;
                 }
                 
                 // Add the entity to the cache.

Modified: code/branches/presentation/src/modules/objects/triggers/MultiTriggerContainer.cc
===================================================================
--- code/branches/presentation/src/modules/objects/triggers/MultiTriggerContainer.cc	2011-05-29 15:46:39 UTC (rev 8666)
+++ code/branches/presentation/src/modules/objects/triggers/MultiTriggerContainer.cc	2011-05-29 16:44:45 UTC (rev 8667)
@@ -72,7 +72,7 @@
         if(pawn != NULL)
         {
             this->setForPlayer(true);
-            this->setTriggeringPlayer(pawn);
+            this->setTriggeringPawn(pawn);
         }
     }
 

Modified: code/branches/presentation/src/modules/questsystem/QuestEffectBeacon.cc
===================================================================
--- code/branches/presentation/src/modules/questsystem/QuestEffectBeacon.cc	2011-05-29 15:46:39 UTC (rev 8666)
+++ code/branches/presentation/src/modules/questsystem/QuestEffectBeacon.cc	2011-05-29 16:44:45 UTC (rev 8667)
@@ -112,7 +112,7 @@
         }
 
         PlayerTrigger* pTrigger = orxonox_cast<PlayerTrigger*>(trigger);
-        Pawn* pawn = NULL;
+        PlayerInfo* player = NULL;
 
         // If the trigger is a PlayerTrigger.
         if(pTrigger != NULL)
@@ -120,26 +120,17 @@
             if(!pTrigger->isForPlayer())  // The PlayerTrigger is not exclusively for Pawns which means we cannot extract one.
                 return false;
             else
-                pawn = pTrigger->getTriggeringPlayer();
+                player = pTrigger->getTriggeringPlayer();
         }
         else
             return false;
 
-        if(pawn == NULL)
+        if(player == NULL)
         {
             COUT(4) << "The QuestEffectBeacon was triggered by an entity other than a Pawn. (" << trigger->getIdentifier()->getName() << ")" << std::endl;
             return false;
         }
 
-        // Extract the PlayerInfo from the Pawn.
-        PlayerInfo* player = pawn->getPlayer();
-
-        if(player == NULL)
-        {
-            COUT(3) << "The PlayerInfo* is NULL." << std::endl;
-            return false;
-        }
-
         COUT(4) << "QuestEffectBeacon executed on player: " << player << " ." << std::endl;
 
         bool temp = QuestEffect::invokeEffects(player, this->effects_); // Invoke the QuestEffects on the PlayerInfo.

Modified: code/branches/presentation/src/orxonox/interfaces/InterfaceCompilation.cc
===================================================================
--- code/branches/presentation/src/orxonox/interfaces/InterfaceCompilation.cc	2011-05-29 15:46:39 UTC (rev 8666)
+++ code/branches/presentation/src/orxonox/interfaces/InterfaceCompilation.cc	2011-05-29 16:44:45 UTC (rev 8667)
@@ -58,7 +58,6 @@
     {
         RegisterRootObject(PlayerTrigger);
 
-        this->player_ = NULL;
         this->isForPlayer_ = false;
     }
 

Modified: code/branches/presentation/src/orxonox/interfaces/PlayerTrigger.h
===================================================================
--- code/branches/presentation/src/orxonox/interfaces/PlayerTrigger.h	2011-05-29 15:46:39 UTC (rev 8666)
+++ code/branches/presentation/src/orxonox/interfaces/PlayerTrigger.h	2011-05-29 16:44:45 UTC (rev 8667)
@@ -39,11 +39,14 @@
 
 #include "core/OrxonoxClass.h"
 
+#include "infos/PlayerInfo.h"
+#include "worldentities/pawns/Pawn.h"
+
 namespace orxonox
 {
     /**
     @brief
-        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.
+        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.
 
     @author
         Damian 'Mozork' Frick
@@ -57,15 +60,22 @@
         virtual ~PlayerTrigger() {}
 
         /**
-        @brief Returns the player that triggered the PlayerTrigger.
+        @brief Returns the Pawn that triggered the PlayerTrigger.
         @return Returns a pointer to the Pawn that triggered the PlayerTrigger.
         */
-        inline Pawn* getTriggeringPlayer(void) const
+        inline Pawn* getTriggeringPawn(void) const
+            { return this->pawn_.get(); }
+
+        /**
+        @brief Returns the player that triggered the PlayerTrigger.
+        @return Returns a pointer to the PlayerInfo that triggered the PlayerTrigger.
+        */
+        inline PlayerInfo* getTriggeringPlayer(void) const
             { return this->player_; }
 
         /**
-        @brief Checks whether the PlayerTrigger normally returns a Pawn.
-        @return Returns true if the PlayerTrigger normally returns a Pawn.
+        @brief Checks whether the PlayerTrigger normally returns a Pawn/PlayerInfo.
+        @return Returns true if the PlayerTrigger normally returns a Pawn/PlayerInfo.
         */
         inline bool isForPlayer(void) const
            { return this->isForPlayer_; }
@@ -75,8 +85,8 @@
         @brief Set the player that triggered the PlayerTrigger. This is normally done by classes inheriting vom PlayerTrigger.
         @param player A pointer to the Pawn that triggered the PlayerTrigger.
         */
-        inline void setTriggeringPlayer(Pawn* player)
-           { this->player_ = player; }
+        inline void setTriggeringPawn(Pawn* pawn)
+           { assert(pawn); this->player_ = WeakPtr<PlayerInfo>(pawn->getPlayer()); this->pawn_ = WeakPtr<Pawn>(pawn); }
 
         /**
         @brief Set whether the PlayerTrigger normally is triggered by Pawns.
@@ -86,7 +96,8 @@
            { this->isForPlayer_ = isForPlayer; }
 
     private:
-        Pawn* player_; //!< The player that triggered the PlayerTrigger.
+        WeakPtr<PlayerInfo> player_; //!< The player that triggered the PlayerTrigger.
+        WeakPtr<Pawn> pawn_; //!< The Pawn that triggered the PlayerTrigger.
         bool isForPlayer_; //!< Is true when the PlayerTrigger should be set to normally be triggered by Pawns.
 
     };




More information about the Orxonox-commit mailing list