Bug in GuiControl mFirstResponder (and fix)
by William Todd Scott · in Torque Game Engine Advanced · 08/07/2007 (3:34 pm) · 1 replies
Hi,
I tracked down a crash bug related to the first responder in the GuiControl class. It is possible for the object this is currently set as the first responder (indicated by mFirstResponder) to be deleted. This causes a problem in the GuiCanvas code because the mFirstResponder pointer is now invalid, but it is not set to NULL.
I was able to consistently duplicate this bug by going into the editor, select an object for inspection, lock the object, and click anywhere. The crash is caused by the inspector gui deleting its members, one of which is set as the first responder.
The fix I employed was to use the built-in deleteNotify() functionality of SimObjects.
In GuiControl.h add the following function declaration at line 44 under the onLoseFirstRepsonder() declaration:
In GuiControl.cpp modify the code starting at 1412 by adding the code indicated in the TG-BEGIN, TG-END blocks:
Todd
//edited for clarity
I tracked down a crash bug related to the first responder in the GuiControl class. It is possible for the object this is currently set as the first responder (indicated by mFirstResponder) to be deleted. This causes a problem in the GuiCanvas code because the mFirstResponder pointer is now invalid, but it is not set to NULL.
I was able to consistently duplicate this bug by going into the editor, select an object for inspection, lock the object, and click anywhere. The crash is caused by the inspector gui deleting its members, one of which is set as the first responder.
The fix I employed was to use the built-in deleteNotify() functionality of SimObjects.
In GuiControl.h add the following function declaration at line 44 under the onLoseFirstRepsonder() declaration:
void GuiControl::onDeleteNotify(SimObject * obj);
In GuiControl.cpp modify the code starting at 1412 by adding the code indicated in the TG-BEGIN, TG-END blocks:
void GuiControl::setFirstResponder( GuiControl* firstResponder )
{
if ( firstResponder && firstResponder->mProfile->mCanKeyFocus )
{
//TG-BEGIN: Fix bug where first responder gets deleted
if(mFirstResponder)
clearNotify(mFirstResponder);
mFirstResponder = firstResponder;
deleteNotify(mFirstResponder);
//TG-END
}
GuiControl *parent = getParent();
if ( parent )
parent->setFirstResponder( firstResponder );
}
//TG-BEGIN: Fix bug where first responder gets deleted
void GuiControl::onDeleteNotify(SimObject * obj)
{
mFirstResponder = NULL;
}
//TG-ENDTodd
//edited for clarity
Torque Owner William Todd Scott
Todd