Browse Source

Bugfix: Fixing a crash when attempting to remove physics objects from the scene, or exit play mode
- Also updated box/sphere collider default size values to non-zero

BearishSun 8 years ago
parent
commit
12d82b99df

+ 5 - 0
Source/BansheeCore/Components/BsCBoxCollider.cpp

@@ -7,6 +7,11 @@
 
 namespace bs
 {
+	CBoxCollider::CBoxCollider()
+	{
+		setName("BoxCollider");
+	}
+
 	CBoxCollider::CBoxCollider(const HSceneObject& parent, const Vector3& extents)
 		: CCollider(parent), mExtents(extents)
 	{

+ 2 - 2
Source/BansheeCore/Components/BsCBoxCollider.h

@@ -57,7 +57,7 @@ namespace bs
 		SPtr<Collider> createInternal() override;
 
 	protected:
-		Vector3 mExtents = Vector3::ZERO;
+		Vector3 mExtents = Vector3::ONE;
 
 		/************************************************************************/
 		/* 								RTTI		                     		*/
@@ -68,7 +68,7 @@ namespace bs
 		RTTITypeBase* getRTTI() const override;
 
 	protected:
-		CBoxCollider() {} // Serialization only
+		CBoxCollider(); // Serialization only
 	};
 
 	 /** @} */

+ 5 - 0
Source/BansheeCore/Components/BsCCapsuleCollider.cpp

@@ -7,6 +7,11 @@
 
 namespace bs
 {
+	CCapsuleCollider::CCapsuleCollider()
+	{
+		setName("CapsuleCollider");
+	}
+
 	CCapsuleCollider::CCapsuleCollider(const HSceneObject& parent, float radius, float halfHeight)
 		: CCollider(parent), mRadius(radius), mHalfHeight(halfHeight)
 	{

+ 1 - 1
Source/BansheeCore/Components/BsCCapsuleCollider.h

@@ -86,7 +86,7 @@ namespace bs
 		RTTITypeBase* getRTTI() const override;
 
 	protected:
-		CCapsuleCollider() {} // Serialization only
+		CCapsuleCollider(); // Serialization only
 	};
 
 	 /** @} */

+ 12 - 2
Source/BansheeCore/Components/BsCCharacterController.cpp

@@ -9,6 +9,13 @@ using namespace std::placeholders;
 
 namespace bs
 {
+	CCharacterController::CCharacterController()
+	{
+		setName("CharacterController");
+
+		mNotifyFlags = TCF_Transform;
+	}
+
 	CCharacterController::CCharacterController(const HSceneObject& parent)
 		: Component(parent)
 	{
@@ -183,8 +190,11 @@ namespace bs
 	void CCharacterController::destroyInternal()
 	{
 		// This should release the last reference and destroy the internal controller
-		mInternal->_setOwner(PhysicsOwnerType::None, nullptr);
-		mInternal = nullptr;
+		if(mInternal)
+		{
+			mInternal->_setOwner(PhysicsOwnerType::None, nullptr);
+			mInternal = nullptr;
+		}
 	}
 
 	void CCharacterController::triggerOnColliderHit(const ControllerColliderCollision& value)

+ 1 - 1
Source/BansheeCore/Components/BsCCharacterController.h

@@ -181,7 +181,7 @@ namespace bs
 		RTTITypeBase* getRTTI() const override;
 
 	protected:
-		CCharacterController() {} // Serialization only
+		CCharacterController(); // Serialization only
 	 };
 
 	 /** @} */

+ 12 - 2
Source/BansheeCore/Components/BsCCollider.cpp

@@ -10,6 +10,13 @@ using namespace std::placeholders;
 
 namespace bs
 {
+	CCollider::CCollider()
+	{
+		setName("Collider");
+
+		mNotifyFlags = (TransformChangedFlags)(TCF_Parent | TCF_Transform);
+	}
+
 	CCollider::CCollider(const HSceneObject& parent)
 		: Component(parent)
 	{
@@ -205,8 +212,11 @@ namespace bs
 		mParent = nullptr;
 
 		// This should release the last reference and destroy the internal collider
-		mInternal->_setOwner(PhysicsOwnerType::None, nullptr);
-		mInternal = nullptr;
+		if(mInternal)
+		{
+			mInternal->_setOwner(PhysicsOwnerType::None, nullptr);
+			mInternal = nullptr;
+		}
 	}
 
 	void CCollider::updateParentRigidbody()

+ 3 - 3
Source/BansheeCore/Components/BsCCollider.h

@@ -132,7 +132,7 @@ namespace bs
 		/** @copydoc Component::onTransformChanged() */
 		void onTransformChanged(TransformChangedFlags flags) override;
 
-    protected:
+	protected:
 		using Component::destroyInternal;
 
 		/** Creates the internal representation of the Collider for use by the component. */
@@ -202,8 +202,8 @@ namespace bs
 		RTTITypeBase* getRTTI() const override;
 
 	protected:
-		CCollider() {} // Serialization only
-     };
+		CCollider(); // Serialization only
+	 };
 
 	 /** @} */
 }

+ 3 - 1
Source/BansheeCore/Components/BsCD6Joint.cpp

@@ -8,7 +8,9 @@ namespace bs
 {
 	CD6Joint::CD6Joint()
 		: CJoint(mDesc)
-	{ }
+	{
+		setName("D6Joint");
+	}
 
 	CD6Joint::CD6Joint(const HSceneObject& parent)
 		: CJoint(parent, mDesc)

+ 3 - 1
Source/BansheeCore/Components/BsCDistanceJoint.cpp

@@ -8,7 +8,9 @@ namespace bs
 {
 	CDistanceJoint::CDistanceJoint()
 		: CJoint(mDesc)
-	{ }
+	{
+		setName("DistanceJoint");
+	}
 
 	CDistanceJoint::CDistanceJoint(const HSceneObject& parent)
 		: CJoint(parent, mDesc)

+ 1 - 1
Source/BansheeCore/Components/BsCDistanceJoint.h

@@ -95,7 +95,7 @@ namespace bs
 		RTTITypeBase* getRTTI() const override;
 
 	protected:
-		CDistanceJoint();// Serialization only
+		CDistanceJoint(); // Serialization only
 	};
 
 	 /** @} */

+ 3 - 1
Source/BansheeCore/Components/BsCFixedJoint.cpp

@@ -9,7 +9,9 @@ namespace bs
 {
 	CFixedJoint::CFixedJoint() 
 		:CJoint(mDesc)
-	{ }
+	{
+		setName("FixedJoint");
+	}
 
 	CFixedJoint::CFixedJoint(const HSceneObject& parent)
 		: CJoint(parent, mDesc)

+ 3 - 1
Source/BansheeCore/Components/BsCHingeJoint.cpp

@@ -8,7 +8,9 @@ namespace bs
 {
 	CHingeJoint::CHingeJoint()
 		: CJoint(mDesc)
-	{ }
+	{
+		setName("HingeJoint");
+	}
 
 	CHingeJoint::CHingeJoint(const HSceneObject& parent)
 		: CJoint(parent, mDesc)

+ 5 - 2
Source/BansheeCore/Components/BsCJoint.cpp

@@ -217,8 +217,11 @@ namespace bs
 	void CJoint::destroyInternal()
 	{
 		// This should release the last reference and destroy the internal joint
-		mInternal->_setOwner(PhysicsOwnerType::None, nullptr);
-		mInternal = nullptr;
+		if(mInternal)
+		{
+			mInternal->_setOwner(PhysicsOwnerType::None, nullptr);
+			mInternal = nullptr;
+		}
 	}
 
 	void CJoint::notifyRigidbodyMoved(const HRigidbody& body)

+ 5 - 0
Source/BansheeCore/Components/BsCMeshCollider.cpp

@@ -8,6 +8,11 @@
 
 namespace bs
 {
+	CMeshCollider::CMeshCollider()
+	{
+		setName("MeshCollider");
+	}
+
 	CMeshCollider::CMeshCollider(const HSceneObject& parent)
 		: CCollider(parent)
 	{

+ 1 - 1
Source/BansheeCore/Components/BsCMeshCollider.h

@@ -63,7 +63,7 @@ namespace bs
 		RTTITypeBase* getRTTI() const override;
 
 	protected:
-		CMeshCollider() {} // Serialization only
+		CMeshCollider(); // Serialization only
 	};
 
 	 /** @} */

+ 5 - 0
Source/BansheeCore/Components/BsCPlaneCollider.cpp

@@ -7,6 +7,11 @@
 
 namespace bs
 {
+	CPlaneCollider::CPlaneCollider()
+	{
+		setName("PlaneCollider");
+	}
+
 	CPlaneCollider::CPlaneCollider(const HSceneObject& parent)
 		: CCollider(parent)
 	{

+ 1 - 1
Source/BansheeCore/Components/BsCPlaneCollider.h

@@ -72,7 +72,7 @@ namespace bs
 		RTTITypeBase* getRTTI() const override;
 
 	protected:
-		CPlaneCollider() {} // Serialization only
+		CPlaneCollider(); // Serialization only
 	};
 
 	 /** @} */

+ 12 - 2
Source/BansheeCore/Components/BsCRigidbody.cpp

@@ -10,6 +10,13 @@ using namespace std::placeholders;
 
 namespace bs
 {
+	CRigidbody::CRigidbody()
+	{
+		setName("Rigidbody");
+
+		mNotifyFlags = (TransformChangedFlags)(TCF_Parent | TCF_Transform);
+	}
+
 	CRigidbody::CRigidbody(const HSceneObject& parent)
 		: Component(parent)
 	{
@@ -384,8 +391,11 @@ namespace bs
 	{
 		clearColliders();
 
-		mInternal->_setOwner(PhysicsOwnerType::None, nullptr);
-		mInternal = nullptr;
+		if(mInternal)
+		{
+			mInternal->_setOwner(PhysicsOwnerType::None, nullptr);
+			mInternal = nullptr;
+		}
 	}
 
 	void CRigidbody::triggerOnCollisionBegin(const CollisionDataRaw& data)

+ 2 - 2
Source/BansheeCore/Components/BsCRigidbody.h

@@ -234,7 +234,7 @@ namespace bs
 
 		/** 
 		 * Registers a new collider with the Rigidbody. This collider will then be used to calculate Rigidbody's geometry
-         * used for collisions, and optionally (depending on set flags) total mass, inertia tensors and center of mass.
+		 * used for collisions, and optionally (depending on set flags) total mass, inertia tensors and center of mass.
 		 */
 		void addCollider(const HCollider& collider);
 
@@ -308,7 +308,7 @@ namespace bs
 		RTTITypeBase* getRTTI() const override;
 
 	protected:
-		CRigidbody() {} // Serialization only
+		CRigidbody(); // Serialization only
 	};
 
 	/** @} */

+ 3 - 1
Source/BansheeCore/Components/BsCSliderJoint.cpp

@@ -9,7 +9,9 @@ namespace bs
 {
 	CSliderJoint::CSliderJoint()
 		: CJoint(mDesc)
-	{ }
+	{
+		setName("SliderJoint");
+	}
 
 	CSliderJoint::CSliderJoint(const HSceneObject& parent)
 		: CJoint(parent, mDesc)

+ 5 - 0
Source/BansheeCore/Components/BsCSphereCollider.cpp

@@ -7,6 +7,11 @@
 
 namespace bs
 {
+	CSphereCollider::CSphereCollider()
+	{
+		setName("SphereCollider");
+	}
+
 	CSphereCollider::CSphereCollider(const HSceneObject& parent, float radius)
 		: CCollider(parent), mRadius(radius)
 	{

+ 2 - 2
Source/BansheeCore/Components/BsCSphereCollider.h

@@ -57,7 +57,7 @@ namespace bs
 		SPtr<Collider> createInternal() override;
 
 	protected:
-		float mRadius;
+		float mRadius = 1.0f;
 
 		/************************************************************************/
 		/* 								RTTI		                     		*/
@@ -68,7 +68,7 @@ namespace bs
 		RTTITypeBase* getRTTI() const override;
 
 	protected:
-		CSphereCollider() {} // Serialization only
+		CSphereCollider(); // Serialization only
 	};
 
 	 /** @} */

+ 3 - 1
Source/BansheeCore/Components/BsCSphericalJoint.cpp

@@ -8,7 +8,9 @@ namespace bs
 {
 	CSphericalJoint::CSphericalJoint()
 		: CJoint(mDesc)
-	{ }
+	{
+		setName("SphericalJoint");
+	}
 
 	CSphericalJoint::CSphericalJoint(const HSceneObject& parent)
 		: CJoint(parent, mDesc)