Fix VM stack corruption

This commit is contained in:
samisalreadytaken 2022-01-27 00:22:00 +03:00
parent aac91b6487
commit 439d3c75ab

View File

@ -1699,7 +1699,9 @@ struct SquirrelSafeCheck
~SquirrelSafeCheck()
{
if (top_ != (sq_gettop(vm_) - outputCount_))
SQInteger curtop = sq_gettop(vm_);
SQInteger diff = curtop - outputCount_;
if ( top_ != diff )
{
Assert(!"Squirrel VM stack is not consistent");
Error("Squirrel VM stack is not consistent\n");
@ -2352,6 +2354,8 @@ bool SquirrelVM::ScopeIsHooked( HSCRIPT hScope, const char *pszEventName )
if (!hScope)
return true;
SquirrelSafeCheck safeCheck(vm_);
Assert(hScope != INVALID_HSCRIPT);
sq_pushroottable(vm_);
@ -2371,7 +2375,7 @@ bool SquirrelVM::ScopeIsHooked( HSCRIPT hScope, const char *pszEventName )
return false;
}
sq_pop(vm_, 3);
sq_pop(vm_, 4);
return val ? true : false;
}
@ -2391,6 +2395,8 @@ HSCRIPT SquirrelVM::LookupHookFunction(const char *pszEventName, HSCRIPT hScope,
if (!ScopeIsHooked(hScope, pszEventName))
return nullptr;
SquirrelSafeCheck safeCheck(vm_);
sq_pushroottable(vm_);
sq_pushstring(vm_, "Hooks", -1);
sq_get(vm_, -2);
@ -2401,7 +2407,7 @@ HSCRIPT SquirrelVM::LookupHookFunction(const char *pszEventName, HSCRIPT hScope,
sq_resetobject(&obj);
sq_getstackobj(vm_, -1, &obj);
sq_addref(vm_, &obj);
sq_pop(vm_, 2);
sq_pop(vm_, 3);
HSQOBJECT* pObj = new HSQOBJECT;
*pObj = obj;