Game Development Community

Crash bug in GuiTextEditCtrl

by Tom Spilman · in Torque Game Engine · 04/26/2006 (2:43 pm) · 0 replies

Found a crash bug in GuiTextEditCtrl from 1.4.

If you go from a history size of zero to whatever size in the gui editor, it doesn't create the history buffer until the GUI is unloaded and reloaded. Because of this GuiTextEditCtrl::updateHistory() will crash as it only checks for mHistorySize > 0 and not that mHistoryBuf != NULL.

The fix is to add a inspectPreApply() and inspectPostApply():

void GuiTextEditCtrl::inspectPreApply()
{
   Parent::inspectPreApply();

   // Delete the current buffer to be rebuilt
   // later in inspectPostApply.
   if ( mHistoryBuf )
   {
      for (S32 i = 0; i < mHistorySize; i++)
         delete [] mHistoryBuf[i];

      delete [] mHistoryBuf;
   }
}

void GuiTextEditCtrl::inspectPostApply()
{
   Parent::inspectPostApply();

   // Rebuild the history buffer.
   if ( mHistorySize > 0 )
   {
      mHistoryBuf = new UTF8*[mHistorySize];
      for ( S32 i = 0; i < mHistorySize; i++ )
      {
         mHistoryBuf[i] = new UTF8[GuiTextCtrl::MAX_STRING_LENGTH + 1];
         mHistoryBuf[i][0] = '[[6281d7d26e0a0]]';
      }
   }
}

This fix could be improved (could store the contents of the history between size changes), but for now it cleans up the crash bug.

About the author

Tom is a programmer and co-owner of Sickhead Games, LLC.