From 3fc16d402514550206709c87616657ce7c0933ea Mon Sep 17 00:00:00 2001 From: Ignacio Etcheverry Date: Wed, 9 Mar 2016 19:52:15 +0100 Subject: [PATCH] Fix crash when resizing ConcavePolygonShape2D segments --- servers/physics_2d/shape_2d_sw.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/servers/physics_2d/shape_2d_sw.cpp b/servers/physics_2d/shape_2d_sw.cpp index 3054ba8d591..5f5a9103a43 100644 --- a/servers/physics_2d/shape_2d_sw.cpp +++ b/servers/physics_2d/shape_2d_sw.cpp @@ -968,19 +968,25 @@ void ConcavePolygonShape2DSW::set_data(const Variant& p_data) { ERR_FAIL_COND(p_data.get_type()!=Variant::VECTOR2_ARRAY && p_data.get_type()!=Variant::REAL_ARRAY); - segments.clear();; - points.clear();; - bvh.clear();; - bvh_depth=1; - Rect2 aabb; if (p_data.get_type()==Variant::VECTOR2_ARRAY) { DVector p2arr = p_data; int len = p2arr.size(); - DVector::Read arr = p2arr.read(); + ERR_FAIL_COND(len%2); + segments.clear(); + points.clear(); + bvh.clear(); + bvh_depth=1; + + if (len==0) { + configure(aabb); + return; + } + + DVector::Read arr = p2arr.read(); Map pointmap; for(int i=0;i