Browse Source

Workaround for resetting mass in CreateFixture() and DestroyFixture()

1vanK 8 years ago
parent
commit
93b880d7d2
1 changed files with 8 additions and 0 deletions
  1. 8 0
      Source/Urho3D/Urho2D/CollisionShape2D.cpp

+ 8 - 0
Source/Urho3D/Urho2D/CollisionShape2D.cpp

@@ -223,7 +223,11 @@ void CollisionShape2D::CreateFixture()
     // Chain shape must have atleast two vertices before creating fixture
     // Chain shape must have atleast two vertices before creating fixture
     if (fixtureDef_.shape->m_type != b2Shape::e_chain || static_cast<const b2ChainShape*>(fixtureDef_.shape)->m_count >= 2)
     if (fixtureDef_.shape->m_type != b2Shape::e_chain || static_cast<const b2ChainShape*>(fixtureDef_.shape)->m_count >= 2)
     {
     {
+        b2MassData massData;
+        body->GetMassData(&massData);
         fixture_ = body->CreateFixture(&fixtureDef_);
         fixture_ = body->CreateFixture(&fixtureDef_);
+        if (!rigidBody_->GetUseFixtureMass()) // Workaround for resetting mass in CreateFixture().
+            body->SetMassData(&massData);
         fixture_->SetUserData(this);
         fixture_->SetUserData(this);
     }
     }
 }
 }
@@ -240,7 +244,11 @@ void CollisionShape2D::ReleaseFixture()
     if (!body)
     if (!body)
         return;
         return;
 
 
+    b2MassData massData;
+    body->GetMassData(&massData);
     body->DestroyFixture(fixture_);
     body->DestroyFixture(fixture_);
+    if (!rigidBody_->GetUseFixtureMass()) // Workaround for resetting mass in DestroyFixture().
+        body->SetMassData(&massData);
     fixture_ = 0;
     fixture_ = 0;
 }
 }