[colobot] 11/74: Fix not calling destructors after save/reload

Didier Raboud odyx at moszumanska.debian.org
Mon Nov 7 07:49:59 UTC 2016


This is an automated email from the git hooks/post-receive script.

odyx pushed a commit to branch debian/master
in repository colobot.

commit 48666c4604a5fbe897c7609767e4ee1ca4da5b35
Author: melex750 <melex750 at users.noreply.github.com>
Date:   Wed Aug 3 17:42:10 2016 -0400

    Fix not calling destructors after save/reload
---
 src/CBot/CBotStack.cpp | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/src/CBot/CBotStack.cpp b/src/CBot/CBotStack.cpp
index 3170fb7..27c648f 100644
--- a/src/CBot/CBotStack.cpp
+++ b/src/CBot/CBotStack.cpp
@@ -760,7 +760,17 @@ bool CBotVar::Save0State(FILE* pf)
     if (!WriteWord(pf, 100+static_cast<int>(m_mPrivate)))return false;        // private variable?
     if (!WriteWord(pf, m_bStatic))return false;                // static variable?
     if (!WriteWord(pf, m_type.GetType()))return false;        // saves the type (always non-zero)
-    if (!WriteWord(pf, static_cast<unsigned short>(m_binit))) return false;                // variable defined?
+
+    if (m_type.Eq(CBotTypPointer) && GetPointer() != nullptr)
+    {
+        if (GetPointer()->m_bConstructor)                    // constructor was called?
+        {
+            if (!WriteWord(pf, (2000 + static_cast<unsigned short>(m_binit)) )) return false;
+            return WriteString(pf, m_token->GetString());    // and variable name
+        }
+    }
+
+    if (!WriteWord(pf, static_cast<unsigned short>(m_binit))) return false;          // variable defined?
     return WriteString(pf, m_token->GetString());            // and variable name
 }
 
@@ -800,6 +810,13 @@ bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar)
         if ( w == CBotTypClass ) w = CBotTypIntrinsic;            // necessarily intrinsic
 
         if (!ReadWord(pf, wi)) return false;                    // init ?
+        bool bConstructor = false;
+        if (w == CBotTypPointer && wi >= 2000)
+        {
+            wi -= 2000;
+            bConstructor = true;
+        }
+
         CBotVar::InitType initType = static_cast<CBotVar::InitType>(wi);
         if (!ReadString(pf, name)) return false;                // variable name
 
@@ -868,9 +885,10 @@ bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar)
 
         case CBotTypPointer:
         case CBotTypNullPointer:
-            if (!ReadString(pf, s)) return false;
+            if (!ReadString(pf, s)) return false;   // name of the class
             {
-                pNew = CBotVar::Create(token, CBotTypResult(w, s));// creates a variable
+                CBotTypResult ptrType(w, s);
+                pNew = CBotVar::Create(token, ptrType);// creates a variable
 //                CBotVarClass* p = nullptr;
                 long id;
                 ReadLong(pf, id);
@@ -881,6 +899,8 @@ bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar)
                 if ( !CBotVar::RestoreState( pf, pInstance ) ) return false;
                 (static_cast<CBotVarPointer*>(pNew))->SetPointer( pInstance );            // and point over
 
+                if (bConstructor) pNew->ConstructorSet(); // constructor was called
+
 //                if ( p != nullptr ) (static_cast<CBotVarPointer*>(pNew))->SetPointer( p );    // rather this one
 
             }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/colobot.git



More information about the Pkg-games-commits mailing list