Game Development Community

guiStackControl crash on bottom - up configuration [fixed]

by Max Kielland · in Torque Game Builder · 02/11/2013 (9:33 am) · 1 replies

I have a guiStackControl at the bottom of the screen. I need the stack to be built from bottom up (new items appearing at the top) and have the control to move its top position instead of the hight extend to accomondate new items added.

new GuiStackControl(TaskQueue) {
  StackingType = "Vertical";
  HorizStacking = "Left to Right";
  VertStacking = "Bottom to Top";
  Padding = "0";
  canSaveDynamicFields = "0";
  superclass = "TGuiStack";
  class = "TWorkQueue";
  isContainer = "1";
  Profile = "GuiDefaultProfile";
  HorizSizing = "right";
  VertSizing = "bottom";
  Position = "2 2";
  Extent = "75 75";
  MinExtent = "75 75";
  canSave = "1";
  Visible = "1";
  hovertime = "1000";
};

As soon I start either my game or the tgb editor (loading my gui) it crash!

If I change the from VertStacking = "Bottom to Top" to VertStacking = "Top to Bottom" it works, but as you can imagine, the stack is then built from top to bottom.

Does anyone know if this is a confirmed bug and a patch to fix it?

I guess I could have the guiStackControl manually sorted,moved and expanded, but then we lose the whole point with a stack object. I could manage all my items manually.

[EDIT]
I have identified the problem in guiStackCtrl.cc where it tries to fetch a SimSet index of size()-1 that of course will crash if the SimSet is empty.

I'm trying to fix this and came across a very "strange" implementation of how to draw the controls bottom up. Just to be sure that I haven't misunderstood anything can someone (GG?) clearify if a guiStackControl configured for "bottom to up" is suposed to grow downwards or uppwards when controls are added?

#1
02/11/2013 (2:52 pm)
I have fixed the problem and made so it grows upward when "bottom to top" is selected and downwards when "top to bottom" is selected.

in source/gui/containers/guiStackControl.cc around row 125:

void GuiStackControl::stackFromBottom()
{
   // Store the sum of the heights of our controls.
   S32 totalHeight=0;
   Point2I curPos;

   // MK Store bottom position for bottom up alignment.
   Point2I bottomPos;

   // Position and resize everything...
   curPos = bottomPos = getPosition();

   // MK Calculate bottom line for later alignment.
   bottomPos.y = curPos.y+getExtent().y;
   
   // Place each child...
   for(S32 i=size(); i>0; i--)
   {
      // Place control
      GuiControl * gc = dynamic_cast<GuiControl*>(operator [](i-1));

      if(gc && gc->isVisible() )
      {
         // We must place the child...

         // Make it have our width but keep its height
         Point2I childExtent = gc->getExtent();

         gc->resize(curPos - getPosition(), Point2I(getExtent().x, childExtent.y));

         // Update our state...
         curPos.y    += childExtent.y + mPadding;
         totalHeight += childExtent.y + mPadding;
      }
   }
   // Conform our size to the sum of the child sizes.
   if( totalHeight > getExtent().y )
   {
      curPos.x = getExtent().x;
      curPos.y = totalHeight;
      resize(getPosition(), curPos);
   }
   else if( totalHeight < getExtent().y )
   {
      curPos.x = getExtent().x;
      curPos.y = getMax( totalHeight , mMinExtent.y );
      resize(getPosition(), curPos);
   }

   // MK align controller's bottom to our alignment point.
   bottomPos.y -= getExtent().y;
   setPosition(bottomPos);

}

This is basically a copy of void GuiStackControl::stackFromTop() but we read the children backwards instead. I guess this is the original functionality and the control is growing downwards.

I added some extra lines to make it grow upward instead (MK)

Enjoy...