Fix crash on attaching player to entity
authorFoghrye4 <foghrye4@gmail.com>
Sun, 9 Oct 2016 17:40:29 +0000 (20:40 +0300)
committerNer'zhul <nerzhul@users.noreply.github.com>
Wed, 19 Oct 2016 06:40:43 +0000 (08:40 +0200)
Rename "refresh" to "processInitData"

src/content_cao.cpp
src/content_cao.h

index a8e03d6701e1358fc25dfb95dcd5aae96388afe2..88ed43a8c8a37697997f74af3f75a47dd85b7211 100644 (file)
@@ -613,13 +613,28 @@ bool GenericCAO::collideWithObjects()
 void GenericCAO::initialize(const std::string &data)
 {
        infostream<<"GenericCAO: Got init data"<<std::endl;
+       processInitData(data);
+
+       if (m_is_player) {
+               // Check if it's the current player
+               LocalPlayer *player = m_env->getLocalPlayer();
+               if (player && strcmp(player->getName(), m_name.c_str()) == 0) {
+                       m_is_local_player = true;
+                       m_is_visible = false;
+                       player->setCAO(this);
+               }
+               m_env->addPlayerName(m_name.c_str());
+       }
+}
+
+void GenericCAO::processInitData(const std::string &data)
+{
        std::istringstream is(data, std::ios::binary);
        int num_messages = 0;
        // version
        u8 version = readU8(is);
        // check version
-       if(version == 1) // In PROTOCOL_VERSION 14
-       {
+       if (version == 1) { // In PROTOCOL_VERSION 14
                m_name = deSerializeString(is);
                m_is_player = readU8(is);
                m_id = readS16(is);
@@ -627,42 +642,26 @@ void GenericCAO::initialize(const std::string &data)
                m_yaw = readF1000(is);
                m_hp = readS16(is);
                num_messages = readU8(is);
-       }
-       else if(version == 0) // In PROTOCOL_VERSION 13
-       {
+       } else if (version == 0) { // In PROTOCOL_VERSION 13
                m_name = deSerializeString(is);
                m_is_player = readU8(is);
                m_position = readV3F1000(is);
                m_yaw = readF1000(is);
                m_hp = readS16(is);
                num_messages = readU8(is);
-       }
-       else
-       {
+       } else {
                errorstream<<"GenericCAO: Unsupported init data version"
                                <<std::endl;
                return;
        }
 
-       for(int i=0; i<num_messages; i++)
-       {
+       for (int i = 0; i < num_messages; i++) {
                std::string message = deSerializeLongString(is);
                processMessage(message);
        }
 
        pos_translator.init(m_position);
        updateNodePos();
-
-       if (m_is_player) {
-               // Check if it's the current player
-               LocalPlayer *player = m_env->getLocalPlayer();
-               if (player && strcmp(player->getName(), m_name.c_str()) == 0) {
-                       m_is_local_player = true;
-                       m_is_visible = false;
-                       player->setCAO(this);
-               }
-               m_env->addPlayerName(m_name.c_str());
-       }
 }
 
 GenericCAO::~GenericCAO()
@@ -1761,7 +1760,7 @@ void GenericCAO::processMessage(const std::string &data)
                u8 type = readU8(is);
 
                if (GenericCAO *childobj = m_env->getGenericCAO(child_id)) {
-                       childobj->initialize(deSerializeLongString(is));
+                       childobj->processInitData(deSerializeLongString(is));
                } else {
                        m_env->addActiveObject(child_id, type, deSerializeLongString(is));
                }
index cf14a1e18faf3000b94318c3bf64c2482624c032..5b34718140c7512915a90c7d8d3ee554aff96c7b 100644 (file)
@@ -125,6 +125,8 @@ public:
 
        void initialize(const std::string &data);
 
+       void processInitData(const std::string &data);
+
        ClientActiveObject *getParent();
 
        bool getCollisionBox(aabb3f *toset);