Bug Fix: Cleanup of string stack bad Eval
by Tom Spilman · in Torque Game Engine · 06/10/2007 (3:28 pm) · 1 replies
In Torsion i've found cases where an EVAL of an expression like this...
Will return seemingly random results in the watch window. This is because Torque is not clearing the string stack in this particular case and whatever was left from a previous evaluation is returned. To fix this we must change the following in compiledEval.cc/.cpp:
My testing so far shows that this is a good fix. Furthermore looking thru the code in OP_CALLFUNC you'll find several other cases where the string value is cleared like in this section...
So i think this is a good fix and should be added to HEAD.
ObjectThatDoesNotExist.getId();
Will return seemingly random results in the watch window. This is because Torque is not clearing the string stack in this particular case and whatever was left from a previous evaluation is returned. To fix this we must change the following in compiledEval.cc/.cpp:
case OP_CALLFUNC:
{
// ...
else if(callType == FuncCallExprNode::MethodCall)
{
saveObject = gEvalState.thisObject;
gEvalState.thisObject = Sim::findObject(callArgv[1]);
if(!gEvalState.thisObject)
{
gEvalState.thisObject = 0;
Con::warnf(ConsoleLogEntry::General,"%s: Unable to find object: '%s' attempting to call function '%s'", getFileLine(ip-4), callArgv[1], fnName);
STR.setStringValue(""); // ADDED... cleanup the string stack!
break;
}My testing so far shows that this is a good fix. Furthermore looking thru the code in OP_CALLFUNC you'll find several other cases where the string value is cleared like in this section...
if(nsEntry->mType == Namespace::Entry::ScriptFunctionType)
{
if(nsEntry->mFunctionOffset)
nsEntry->mCode->exec(nsEntry->mFunctionOffset, fnName, nsEntry->mNamespace, callArgc, callArgv, false, nsEntry->mPackage);
else // no body
STR.setStringValue("");
}So i think this is a good fix and should be added to HEAD.
About the author
Tom is a programmer and co-owner of Sickhead Games, LLC.
Torque Owner asmaloney (Andy)
Default Studio Name