Fix not calling destructors after save/reload

dev-new-models
melex750 2016-08-03 17:42:10 -04:00
parent 210b5c295d
commit 48666c4604
1 changed files with 23 additions and 3 deletions

View File

@ -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, 100+static_cast<int>(m_mPrivate)))return false; // private variable?
if (!WriteWord(pf, m_bStatic))return false; // static 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, 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 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 ( w == CBotTypClass ) w = CBotTypIntrinsic; // necessarily intrinsic
if (!ReadWord(pf, wi)) return false; // init ? 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); CBotVar::InitType initType = static_cast<CBotVar::InitType>(wi);
if (!ReadString(pf, name)) return false; // variable name if (!ReadString(pf, name)) return false; // variable name
@ -868,9 +885,10 @@ bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar)
case CBotTypPointer: case CBotTypPointer:
case CBotTypNullPointer: 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; // CBotVarClass* p = nullptr;
long id; long id;
ReadLong(pf, id); ReadLong(pf, id);
@ -881,6 +899,8 @@ bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar)
if ( !CBotVar::RestoreState( pf, pInstance ) ) return false; if ( !CBotVar::RestoreState( pf, pInstance ) ) return false;
(static_cast<CBotVarPointer*>(pNew))->SetPointer( pInstance ); // and point over (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 // if ( p != nullptr ) (static_cast<CBotVarPointer*>(pNew))->SetPointer( p ); // rather this one
} }