diff --git a/panda/src/bullet/bulletBodyNode.cxx b/panda/src/bullet/bulletBodyNode.cxx index 6580c79722..cb4d39c444 100644 --- a/panda/src/bullet/bulletBodyNode.cxx +++ b/panda/src/bullet/bulletBodyNode.cxx @@ -45,7 +45,16 @@ BulletBodyNode(const BulletBodyNode ©) : _shapes(copy._shapes) { if (copy._shape && copy._shape->getShapeType() == COMPOUND_SHAPE_PROXYTYPE) { - _shape = new btCompoundShape(copy._shape); + // btCompoundShape does not define a copy constructor. Manually copy. + btCompoundShape *shape = new btCompoundShape; + _shape = shape; + + btCompoundShape *copy_shape = (btCompoundShape *)copy._shape; + int num_children = copy_shape->getNumChildShapes(); + for (int i = 0; i < num_children; ++i) { + shape->addChildShape(copy_shape->getChildTransform(i), + copy_shape->getChildShape(i)); + } } else if (copy._shape && copy._shape->getShapeType() == EMPTY_SHAPE_PROXYTYPE) { _shape = new btEmptyShape(); diff --git a/panda/src/bullet/bulletGhostNode.cxx b/panda/src/bullet/bulletGhostNode.cxx index 8f8c783943..ddead41067 100644 --- a/panda/src/bullet/bulletGhostNode.cxx +++ b/panda/src/bullet/bulletGhostNode.cxx @@ -55,7 +55,7 @@ void BulletGhostNode:: parents_changed() { Parents parents = get_parents(); - for (int i=0; i < parents.get_num_parents(); ++i) { + for (size_t i = 0; i < parents.get_num_parents(); ++i) { PandaNode *parent = parents.get_parent(i); TypeHandle type = parent->get_type(); diff --git a/panda/src/bullet/bulletRigidBodyNode.I b/panda/src/bullet/bulletRigidBodyNode.I index 6be1af948f..de1d5eea05 100644 --- a/panda/src/bullet/bulletRigidBodyNode.I +++ b/panda/src/bullet/bulletRigidBodyNode.I @@ -18,7 +18,6 @@ INLINE BulletRigidBodyNode:: ~BulletRigidBodyNode() { delete _rigid; - delete _motion; } /** diff --git a/panda/src/bullet/bulletRigidBodyNode.cxx b/panda/src/bullet/bulletRigidBodyNode.cxx index 23c6d17afd..5c5e722785 100644 --- a/panda/src/bullet/bulletRigidBodyNode.cxx +++ b/panda/src/bullet/bulletRigidBodyNode.cxx @@ -21,16 +21,12 @@ TypeHandle BulletRigidBodyNode::_type_handle; */ BulletRigidBodyNode:: BulletRigidBodyNode(const char *name) : BulletBodyNode(name) { - - // Motion state - _motion = new MotionState(); - // Mass properties btScalar mass(0.0); btVector3 inertia(0, 0, 0); // construction info - btRigidBody::btRigidBodyConstructionInfo ci(mass, _motion, _shape, inertia); + btRigidBody::btRigidBodyConstructionInfo ci(mass, &_motion, _shape, inertia); // Additional damping if (bullet_additional_damping) { @@ -52,13 +48,13 @@ BulletRigidBodyNode(const char *name) : BulletBodyNode(name) { */ BulletRigidBodyNode:: BulletRigidBodyNode(const BulletRigidBodyNode ©) : - BulletBodyNode(copy) + BulletBodyNode(copy), + _motion(copy._motion) { - _motion = new MotionState(*copy._motion); _rigid = new btRigidBody(*copy._rigid); _rigid->setUserPointer(this); _rigid->setCollisionShape(_shape); - _rigid->setMotionState(_motion); + _rigid->setMotionState(&_motion); } /** @@ -280,7 +276,7 @@ apply_central_impulse(const LVector3 &impulse) { void BulletRigidBodyNode:: transform_changed() { - if (_motion->sync_disabled()) return; + if (_motion.sync_disabled()) return; NodePath np = NodePath::any_path((PandaNode *)this); CPT(TransformState) ts = np.get_net_transform(); @@ -290,7 +286,7 @@ transform_changed() { // transform within the motion state. For dynamic bodies we need to store // the net scale within the motion state, since Bullet might update the // transform via MotionState::setWorldTransform. - _motion->set_net_transform(ts); + _motion.set_net_transform(ts); // For dynamic or static bodies we directly apply the new transform. if (!is_kinematic()) { @@ -334,7 +330,7 @@ sync_p2b() { void BulletRigidBodyNode:: sync_b2p() { - _motion->sync_b2p((PandaNode *)this); + _motion.sync_b2p((PandaNode *)this); } /** @@ -589,7 +585,7 @@ pick_dirty_flag() { bool BulletRigidBodyNode:: pick_dirty_flag() { - return _motion->pick_dirty_flag(); + return _motion.pick_dirty_flag(); } /** diff --git a/panda/src/bullet/bulletRigidBodyNode.h b/panda/src/bullet/bulletRigidBodyNode.h index 42b2495aff..ea59c9202c 100644 --- a/panda/src/bullet/bulletRigidBodyNode.h +++ b/panda/src/bullet/bulletRigidBodyNode.h @@ -124,7 +124,7 @@ private: bool _was_dirty; }; - MotionState *_motion; + MotionState _motion; btRigidBody *_rigid; public: