Game Development Community

[Beta 4 Bug w/ Fix] Rollout Collapse

by Ryan Mounts · in Torque 3D Professional · 07/28/2009 (9:47 am) · 0 replies

There is a bug in the collapse method of the GuiRolloutCtrl, which can be demonstrated easily. Create a new GuiRolloutCtrl and issue the console command: %myNewRollout.collapse();

The rollout collapses.

Now issue the same command again: %myNewRollout.collapse();

The rollout expands.

So instead of collapsing the rollout as expected, the collapse method actually toggles the rollout state. The bug can be found and fixed in the "GuiRolloutCtrl::animateTo()" method in "guiRolloutCtrl.cpp" around line 268. Change the two if-statements from this:

bool collapsing = (bool)( getHeight() > height );

   // If we're already at the destination height, bail
   if ( getHeight() >= height && !collapsing )
   {
      mIsExpanded = true;
      return;
   }

   // If we're already at the destination height, bail
   if ( getHeight() <= height && collapsing )
   {
      mIsExpanded = false;
      return;
   }

to this:

bool collapsing = (bool)( getHeight() > height );

   // If we're already at the destination height, bail
   if ( getHeight() == height && height == mExpanded.extent.y )    // This line changed
   {
      mIsExpanded = true;
      return;
   }

   // If we're already at the destination height, bail
   if ( getHeight() == height && height == mHeader.extent.y )      // This line changed
   {
      mIsExpanded = false;
      return;
   }

The logic of the first statement allowed for already collapsed rollouts to be flagged as "isExpanded = true" which causes them to toggle. The logic of the second statement made it unreachable code.