Browse Source

Tiled-box decorator: Fix crash on unspecified corner textures (see #22).

Michael Ragazzon 6 years ago
parent
commit
ba678a7542
2 changed files with 34 additions and 18 deletions
  1. 14 1
      Samples/basic/demo/data/demo.rml
  2. 20 17
      Source/Core/DecoratorTiledBox.cpp

+ 14 - 1
Samples/basic/demo/data/demo.rml

@@ -117,6 +117,19 @@ button:focus {
 	decorator: ninepatch(button-active, button-inner-active);
 }
 
+@decorator left-arrow : tiled-box {
+	top-image-src: ../../../assets/present.tga;
+	center-image-src: ../../../assets/present.tga;
+	left-image-src: ../../../assets/present.tga;
+}
+
+.left-arrow {
+	width: 32dp;
+	height: 32dp;
+	decorator: left-arrow;
+}
+
+
 </style>
 </head>
 
@@ -159,6 +172,6 @@ button:focus {
 	<textarea cols="30" rows="5" wrap="nowrap">Hello World!</textarea>
 </panel>
 </tabset>
-
+<div class="left-arrow"/>
 </body>
 </rml>

+ 20 - 17
Source/Core/DecoratorTiledBox.cpp

@@ -70,6 +70,16 @@ bool DecoratorTiledBox::Initialise(const Tile* _tiles, const Texture* _textures)
 		tiles[i].texture_index = AddTexture(_textures[i]);
 	}
 
+	// All corners must have a valid texture.
+	for (int i = TOP_LEFT_CORNER; i <= BOTTOM_RIGHT_CORNER; i++)
+	{
+		if (tiles[i].texture_index == -1)
+			return false;
+	}
+	// Check that the centre tile has been specified.
+	if (tiles[CENTRE].texture_index < 0)
+		return false;
+
 	// If only one side of the left / right edges have been configured, then mirror the tile for the other side.
 	if (tiles[LEFT_EDGE].texture_index == -1 && tiles[RIGHT_EDGE].texture_index > -1)
 	{
@@ -98,10 +108,6 @@ bool DecoratorTiledBox::Initialise(const Tile* _tiles, const Texture* _textures)
 	else if (tiles[TOP_EDGE].texture_index == -1 && tiles[BOTTOM_EDGE].texture_index == -1)
 		return false;
 
-	// Check that the centre tile has been specified.
-	if (tiles[CENTRE].texture_index < 0)
-		return false;
-
 	return true;
 }
 
@@ -255,19 +261,16 @@ DecoratorDataHandle DecoratorTiledBox::GenerateElementData(Element* element) con
 												bottom_right_dimensions);
 
 	// Generate the centre geometry.
-	if (tiles[CENTRE].texture_index >= 0)
-	{
-		Vector2f centre_dimensions = tiles[CENTRE].GetDimensions(element);
-		Vector2f centre_surface_dimensions(padded_size.x - (left_dimensions.x + right_dimensions.x),
-											  padded_size.y - (top_dimensions.y + bottom_dimensions.y));
-
-		tiles[CENTRE].GenerateGeometry(data->geometry[tiles[CENTRE].texture_index].GetVertices(),
-									   data->geometry[tiles[CENTRE].texture_index].GetIndices(),
-									   element,
-									   Vector2f(left_dimensions.x, top_dimensions.y),
-									   centre_surface_dimensions,
-									   centre_dimensions);
-	}
+	Vector2f centre_dimensions = tiles[CENTRE].GetDimensions(element);
+	Vector2f centre_surface_dimensions(padded_size.x - (left_dimensions.x + right_dimensions.x),
+											padded_size.y - (top_dimensions.y + bottom_dimensions.y));
+
+	tiles[CENTRE].GenerateGeometry(data->geometry[tiles[CENTRE].texture_index].GetVertices(),
+									data->geometry[tiles[CENTRE].texture_index].GetIndices(),
+									element,
+									Vector2f(left_dimensions.x, top_dimensions.y),
+									centre_surface_dimensions,
+									centre_dimensions);
 
 	// Set the textures on the geometry.
 	const Texture* texture = nullptr;