Преглед на файлове

Check vertices count

Check vertices count for chain shape collision before creating fixture.
cosmy1 преди 10 години
родител
ревизия
444695f2a6
променени са 1 файла, в които са добавени 14 реда и са изтрити 2 реда
  1. 14 2
      Source/Urho3D/Urho2D/CollisionShape2D.cpp

+ 14 - 2
Source/Urho3D/Urho2D/CollisionShape2D.cpp

@@ -222,8 +222,20 @@ void CollisionShape2D::CreateFixture()
     if (!body)
         return;
 
-    fixture_ = body->CreateFixture(&fixtureDef_);
-    fixture_->SetUserData(this);
+    // Chain shape must have atleast two vertices before creating fixture
+    if (fixtureDef_.shape->m_type == b2Shape::e_chain)
+    {
+        if (dynamic_cast<const b2ChainShape*>(fixtureDef_.shape)->m_count >= 2)
+        {
+            fixture_ = body->CreateFixture(&fixtureDef_);
+            fixture_->SetUserData(this);
+        }
+    }
+    else
+    {
+        fixture_ = body->CreateFixture(&fixtureDef_);
+        fixture_->SetUserData(this);
+    }
 }
 
 void CollisionShape2D::ReleaseFixture()