瀏覽代碼

Merge pull request #27783 from nekomatata/style-box-errors-fix

Fixed StyleBoxFlat sending an empty list of vertices to render when nothing is visible
Rémi Verschelde 6 年之前
父節點
當前提交
3a0ab0376e
共有 1 個文件被更改,包括 8 次插入5 次删除
  1. 8 5
      scene/resources/style_box.cpp

+ 8 - 5
scene/resources/style_box.cpp

@@ -669,11 +669,15 @@ inline void adapt_values(int p_index_a, int p_index_b, int *adapted_values, cons
 void StyleBoxFlat::draw(RID p_canvas_item, const Rect2 &p_rect) const {
 void StyleBoxFlat::draw(RID p_canvas_item, const Rect2 &p_rect) const {
 
 
 	//PREPARATIONS
 	//PREPARATIONS
+	bool draw_border = (border_width[0] > 0) || (border_width[1] > 0) || (border_width[2] > 0) || (border_width[3] > 0);
+	bool draw_shadow = (shadow_size > 0);
+	if (!draw_border && !draw_center && !draw_shadow) {
+		return;
+	}
 
 
 	bool rounded_corners = (corner_radius[0] > 0) || (corner_radius[1] > 0) || (corner_radius[2] > 0) || (corner_radius[3] > 0);
 	bool rounded_corners = (corner_radius[0] > 0) || (corner_radius[1] > 0) || (corner_radius[2] > 0) || (corner_radius[3] > 0);
 	bool aa_on = rounded_corners && anti_aliased;
 	bool aa_on = rounded_corners && anti_aliased;
 
 
-	bool draw_border = (border_width[0] > 0) || (border_width[1] > 0) || (border_width[2] > 0) || (border_width[3] > 0);
 	Color border_color_alpha = Color(border_color.r, border_color.g, border_color.b, 0);
 	Color border_color_alpha = Color(border_color.r, border_color.g, border_color.b, 0);
 
 
 	bool blend_on = blend_border && draw_border;
 	bool blend_on = blend_border && draw_border;
@@ -710,11 +714,8 @@ void StyleBoxFlat::draw(RID p_canvas_item, const Rect2 &p_rect) const {
 	Vector<int> indices;
 	Vector<int> indices;
 	Vector<Color> colors;
 	Vector<Color> colors;
 
 
-	//DRAWING
-	VisualServer *vs = VisualServer::get_singleton();
-
 	//DRAW SHADOW
 	//DRAW SHADOW
-	if (shadow_size > 0) {
+	if (draw_shadow) {
 		int shadow_width[4] = { shadow_size, shadow_size, shadow_size, shadow_size };
 		int shadow_width[4] = { shadow_size, shadow_size, shadow_size, shadow_size };
 
 
 		Rect2 shadow_inner_rect = style_rect;
 		Rect2 shadow_inner_rect = style_rect;
@@ -798,6 +799,8 @@ void StyleBoxFlat::draw(RID p_canvas_item, const Rect2 &p_rect) const {
 		}
 		}
 	}
 	}
 
 
+	//DRAWING
+	VisualServer *vs = VisualServer::get_singleton();
 	vs->canvas_item_add_triangle_array(p_canvas_item, indices, verts, colors);
 	vs->canvas_item_add_triangle_array(p_canvas_item, indices, verts, colors);
 }
 }