- priority: 5 --> 7
Every VM function for accessing to stack returns SQObjectPtr & (by reference!) that causes errors when the stack reallocates to other memory location. After the stack reallocation all references became not valid, because they were pointed to old memory location.
For example, in sq_get function there is lines:
SQObjectPtr &self=stack_get(v,idx);
if(v->Get(self,v->GetUp(-1),v->GetUp(-1),false,false))
return SQ_OK;
All parameters to Get function are sent by reference. That causes an access violation error.
Let see a call stack:
SQObjectPtr::operator=(const SQObjectPtr & obj={...}) Line 308 + 0xd bytes C++
SQVM::CallNative(SQNativeClosure * nclosure=0x05babd10, int nargs=0x00000002, int stackbase=0x000003f5, SQObjectPtr & retval={...}, bool & suspend=false) Line 1140 + 0x22 bytes C++
SQVM::Call(SQObjectPtr & closure={...}, int nparams=0x00000002, int stackbase=0x000003f5, SQObjectPtr & outres={...}, unsigned int raiseerror=0x00000000) Line 1405 + 0x1f bytes C++
SQVM::CallMetaMethod(SQDelegable * del=0x05bf9f30, SQMetaMethod mm=MT_GET, int nparams=0x00000002, SQObjectPtr & outres={...}) Line 1435 + 0x20 bytes C++
SQVM::FallBackGet(const SQObjectPtr & self={...}, const SQObjectPtr & key={...}, SQObjectPtr & dest={...}, bool raw=false) Line 1219 + 0x17 bytes C++
SQVM::Get(const SQObjectPtr & self={...}, const SQObjectPtr & key={...}, SQObjectPtr & dest={...}, bool raw=false, bool fetchroot=false) Line 1164 + 0x19 bytes C++
sq_get(SQVM * v=0x0063af08, int idx=0xfffffffe) Line 839 + 0x26 bytes C++
In CallNative function there is code on line 1102 for resizing the stack vector. But the retval parameter becomes not valid because it is referenced to old stack memory (that reference was sent as third parameter in SQVM::Get() function in sq_get() body).
I think that all access functions should return result by value. Its more expensive in a perfomance, but there is no other way to
avoid reallocation bug.
P.S. I'm sorry for my tangled explanation and my poor English :)