Browse Source

Added check to Form::setSize() to prevent it from attempting to create a FrameBuffer with a width or height of 0, which would cause the game to crash.
Overrode Control::setWidth() and Control::setHeight() on Form so that they call Form::setSize() in order to create and/or re-size the FrameBuffer.

Adam Blake 13 years ago
parent
commit
6fd8aadef8
3 changed files with 34 additions and 7 deletions
  1. 4 2
      gameplay/src/Control.h
  2. 16 5
      gameplay/src/Form.cpp
  3. 14 0
      gameplay/src/Form.h

+ 4 - 2
gameplay/src/Control.h

@@ -214,13 +214,15 @@ public:
 
 
     /** 
     /** 
      * Set the desired width of the control, including it's border and padding, before clipping.
      * Set the desired width of the control, including it's border and padding, before clipping.
-     * @param width The width;
+     *
+     * @param width The width.
      */
      */
     virtual void setWidth(float width);
     virtual void setWidth(float width);
 
 
     /** 
     /** 
      * Set the desired height of the control, including it's border and padding, before clipping.
      * Set the desired height of the control, including it's border and padding, before clipping.
-     * @param height The height;
+     *
+     * @param height The height.
      */
      */
     virtual void setHeight(float height);
     virtual void setHeight(float height);
 
 

+ 16 - 5
gameplay/src/Form.cpp

@@ -238,7 +238,8 @@ void Form::setSize(float width, float height)
         height = Game::getInstance()->getHeight();
         height = Game::getInstance()->getHeight();
     }
     }
 
 
-    if (width != _bounds.width || height != _bounds.height)
+    if (width != 0.0f && height != 0.0f &&
+        (width != _bounds.width || height != _bounds.height))
     {
     {
         // Width and height must be powers of two to create a texture.
         // Width and height must be powers of two to create a texture.
         unsigned int w = nextPowerOfTwo(width);
         unsigned int w = nextPowerOfTwo(width);
@@ -271,11 +272,11 @@ void Form::setSize(float width, float height)
         _theme->setProjectionMatrix(_defaultProjectionMatrix);
         _theme->setProjectionMatrix(_defaultProjectionMatrix);
         FrameBuffer::bindDefault();
         FrameBuffer::bindDefault();
         game->setViewport(prevViewport);
         game->setViewport(prevViewport);
-
-        _bounds.width = width;
-        _bounds.height = height;
-        _dirty = true;
     }
     }
+    
+    _bounds.width = width;
+    _bounds.height = height;
+    _dirty = true;
 }
 }
 
 
 void Form::setBounds(const Rectangle& bounds)
 void Form::setBounds(const Rectangle& bounds)
@@ -284,6 +285,16 @@ void Form::setBounds(const Rectangle& bounds)
     setSize(bounds.width, bounds.height);
     setSize(bounds.width, bounds.height);
 }
 }
 
 
+void Form::setWidth(float width)
+{
+    setSize(width, _bounds.height);
+}
+
+void Form::setHeight(float height)
+{
+    setSize(_bounds.width, height);
+}
+
 void Form::setAutoWidth(bool autoWidth)
 void Form::setAutoWidth(bool autoWidth)
 {
 {
     if (_autoWidth != autoWidth)
     if (_autoWidth != autoWidth)

+ 14 - 0
gameplay/src/Form.h

@@ -104,6 +104,20 @@ public:
      */
      */
     virtual void setBounds(const Rectangle& bounds);
     virtual void setBounds(const Rectangle& bounds);
 
 
+    /** 
+     * Set the desired width of the form.
+     *
+     * @param width The width.
+     */
+    virtual void setWidth(float width);
+
+    /** 
+     * Set the desired height of the form.
+     *
+     * @param height The height.
+     */
+    virtual void setHeight(float height);
+
     /**
     /**
      * Set this form's width to that of the display.
      * Set this form's width to that of the display.
      *
      *