Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitchell Stokes <mogurijin@gmail.com>2013-11-18 21:30:46 +0400
committerMitchell Stokes <mogurijin@gmail.com>2013-11-18 21:37:58 +0400
commitc73f82b6f07c76705be52d7bb40ee866aea98b9c (patch)
tree9fe7134418403e1685be4cbf659725590c611b6a /source/gameengine
parent2d4bfc5e60e50474e8fc66a44fde3b0bca93edaf (diff)
Fix T37040: Removing vehicles in BGE causes a crash
The vehicle constraint is now properly removed if bge.constraints.removeConstraint() is used or the object is deleted. This also fixes a memory leak with the vehicle wrapper.
Diffstat (limited to 'source/gameengine')
-rw-r--r--source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
index 71ed6af2f99..cddc12cc754 100644
--- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
+++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
@@ -83,6 +83,11 @@ public:
{
}
+ ~WrapperVehicle()
+ {
+ delete m_vehicle;
+ }
+
btRaycastVehicle* GetVehicle()
{
return m_vehicle;
@@ -440,6 +445,19 @@ bool CcdPhysicsEnvironment::RemoveCcdPhysicsController(CcdPhysicsController* ctr
//delete con; //might be kept by python KX_ConstraintWrapper
}
m_dynamicsWorld->removeRigidBody(ctrl->GetRigidBody());
+
+ // Handle potential vehicle constraints
+ int numVehicles = m_wrapperVehicles.size();
+ int vehicle_constraint = 0;
+ for (int i=0;i<numVehicles;i++)
+ {
+ WrapperVehicle* wrapperVehicle = m_wrapperVehicles[i];
+ if (wrapperVehicle->GetChassis() == ctrl)
+ vehicle_constraint = wrapperVehicle->GetVehicle()->getUserConstraintId();
+ }
+
+ if (vehicle_constraint > 0)
+ RemoveConstraint(vehicle_constraint);
} else
{
//if a softbody
@@ -984,6 +1002,14 @@ void CcdPhysicsEnvironment::RemoveConstraint(int constraintId)
break;
}
}
+
+ WrapperVehicle *vehicle;
+ if ((vehicle = (WrapperVehicle*)GetVehicleConstraint(constraintId)))
+ {
+ m_dynamicsWorld->removeVehicle(vehicle->GetVehicle());
+ m_wrapperVehicles.erase(std::remove(m_wrapperVehicles.begin(), m_wrapperVehicles.end(), vehicle));
+ delete vehicle;
+ }
}