Merge pull request #762 from melex750/dev

Fix initializing arrays in class definition
dev-time-step
krzys_h 2016-04-07 21:27:19 +02:00
commit 1941020993
1 changed files with 11 additions and 2 deletions

View File

@ -22,6 +22,7 @@
#include "CBot/CBotInstr/CBotInstrUtils.h"
#include "CBot/CBotInstr/CBotNew.h"
#include "CBot/CBotInstr/CBotLeftExprVar.h"
#include "CBot/CBotInstr/CBotExprLitNull.h"
#include "CBot/CBotInstr/CBotTwoOpExpr.h"
#include "CBot/CBotInstr/CBotFunction.h"
#include "CBot/CBotInstr/CBotExpression.h"
@ -722,6 +723,7 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond)
}
if ( !pStack->IsOk() ) return false;
}
else if ( type2.Eq(CBotTypArrayPointer) ) i = new CBotExprLitNull();
if ( !bSecond )
@ -739,8 +741,15 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond)
if ( pv->IsStatic() && pv->m_InitExpr != nullptr )
{
CBotStack* pile = CBotStack::AllocateStack(); // independent stack
if ( type2.Eq(CBotTypArrayPointer) )
{
while(pile->IsOk() && !pv->m_InitExpr->Execute(pile, pv));
}
else
{
while(pile->IsOk() && !pv->m_InitExpr->Execute(pile)); // evaluates the expression without timer
pv->SetVal( pile->GetVar() ) ;
}
pile->Delete();
}
}