Bug in guiConsoleTextCtrl.cc
by Philip Engdahl · in Torque Game Engine · 01/12/2006 (11:09 pm) · 1 replies
Took me all day to track down this bug :(
There is a bug (design flaw?) in guiConsoleTextCtrl.cc in TGE 1.4 - the mResult member is a pointer to the result of an evaluatef() command, but it should be a string storing the result instead. The reason for this is that if another evaluate() is called after this one is called, the string this pointer points to will be changed. I discovered this problem by turning on the fps metrics and subsequently using the Con::getFloatVariable() commands - the metrics would be overwritten by the result of the Con::getFloatVariable.
Here's my modified guiConsoleTextCtrl.cc (changes in bold):
and here's my modified guiConsoleTextCtrl.h (changes in bold):
There is a bug (design flaw?) in guiConsoleTextCtrl.cc in TGE 1.4 - the mResult member is a pointer to the result of an evaluatef() command, but it should be a string storing the result instead. The reason for this is that if another evaluate() is called after this one is called, the string this pointer points to will be changed. I discovered this problem by turning on the fps metrics and subsequently using the Con::getFloatVariable() commands - the metrics would be overwritten by the result of the Con::getFloatVariable.
Here's my modified guiConsoleTextCtrl.cc (changes in bold):
...
GuiConsoleTextCtrl::GuiConsoleTextCtrl()
{
//default fonts
mConsoleExpression = NULL;
[b]// mResult = NULL;[/b]
[b] mResult[0] = '[[62812ccd3a14c]]';[/b]
}
void GuiConsoleTextCtrl::calcResize()
{
[b] // mResult is a member of this class - hence it will always exist.
// if (!mResult)
// return;[/b]
...
void GuiConsoleTextCtrl::onPreRender()
{
if (mConsoleExpression)
{
[b]dStrncpy( mResult, Con::evaluatef( "%s;", mConsoleExpression ), MAX_STRING_LENGTH );
mResult[MAX_STRING_LENGTH] = '[[62812ccd3a14c]]';
// mResult = Con::evaluatef("$temp = %s;", mConsoleExpression);[/b]
}
calcResize();
}
...
[b] // no need to test mResult
// if (mResult)
// {[/b]
S32 txt_w = mFont->getStrWidth((const UTF8 *)mResult);
Point2I localStart;
...
dglSetBitmapModulation(mProfile->mFontColor);
dglDrawText(mFont, globalStart, mResult, mProfile->mFontColors);
[b]// }[/b]and here's my modified guiConsoleTextCtrl.h (changes in bold):
... protected: const char *mConsoleExpression; [b]// const char *mResult;[/b] [b] UTF8 mResult[MAX_STRING_LENGTH + 1];[/b] Resource<GFont> mFont; ...
About the author
Torque 3D Owner Torbjorn Leksell
Narcissistic Studios