[Bf-blender-cvs] [c73f82b] master: Fix T37040: Removing vehicles in BGE causes a crash
Mitchell Stokes
noreply at git.blender.org
Mon Nov 18 18:39:04 CET 2013
Commit: c73f82b6f07c76705be52d7bb40ee866aea98b9c
Author: Mitchell Stokes
Date: Mon Nov 18 09:30:46 2013 -0800
http://developer.blender.org/rBc73f82b6f07c76705be52d7bb40ee866aea98b9c
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.
===================================================================
M source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
===================================================================
diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
index 71ed6af..cddc12c 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;
+ }
}
More information about the Bf-blender-cvs
mailing list