From c19f97bc24c2c5532db84fd2ba6664fba22f8838 Mon Sep 17 00:00:00 2001 From: melex750 Date: Tue, 24 May 2016 10:09:44 -0400 Subject: [PATCH] Fix RestoreState to assign IDs to instance vars --- src/CBot/CBotStack.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/CBot/CBotStack.cpp b/src/CBot/CBotStack.cpp index 746976b0..3170fb72 100644 --- a/src/CBot/CBotStack.cpp +++ b/src/CBot/CBotStack.cpp @@ -805,6 +805,8 @@ bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar) CBotToken token(name, std::string()); + bool isClass = false; + switch (w) { case CBotTypInt: @@ -826,6 +828,7 @@ bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar) // returns an intrinsic object or element of an array case CBotTypIntrinsic: + isClass = true; case CBotTypArrayBody: { CBotTypResult r; @@ -843,6 +846,17 @@ bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar) if ( !RestoreState(pf, (static_cast(pNew))->m_pVar)) return false; pNew->SetIdent(id); + if (isClass && p == nullptr) // set id for each item in this instance + { + CBotVar* pVars = pNew->GetItemList(); + long itemId = 1; + while (pVars != nullptr) + { + pVars->m_ident = itemId++; + pVars = pVars->GetNext(); + } + } + if ( p != nullptr ) { delete pNew;