Browse Source

Make MouseJoint:getBodies() return only one body (fixes #1179)

Override Joint's Body getters in MouseJoint, to make the second (user-supplied) body the first body returned, and return nil for the second (internal) body
Bart van Strien 9 years ago
parent
commit
65f53a491f

+ 1 - 0
changes.txt

@@ -21,6 +21,7 @@ Released: N/A
   * Fixed the default shader improperly applying gamma correction to per-vertex colors when gamma correction is requested but not supported on OpenGL ES.
   * Fixed text coloring breaking because of an empty string.
   * Fixed large burst of particles when dramatically increasing the emission rate of a ParticleSystem.
+  * Fixed MouseJoint:getBodies unconditionally erroring.
 
   * Improved performance of Channel methods by roughly 2x in many cases.
   

+ 2 - 2
src/modules/physics/box2d/Joint.h

@@ -84,8 +84,8 @@ public:
 	 **/
 	Type getType() const;
 
-	Body *getBodyA() const;
-	Body *getBodyB() const;
+	virtual Body *getBodyA() const;
+	virtual Body *getBodyB() const;
 
 	/**
 	 * Gets the anchor positions of the Joint in world

+ 10 - 0
src/modules/physics/box2d/MouseJoint.cpp

@@ -91,6 +91,16 @@ float MouseJoint::getDampingRatio() const
 	return joint->GetDampingRatio();
 }
 
+Body *MouseJoint::getBodyA() const
+{
+	return Joint::getBodyB();
+}
+
+Body *MouseJoint::getBodyB() const
+{
+	return nullptr;
+}
+
 } // box2d
 } // physics
 } // love

+ 3 - 0
src/modules/physics/box2d/MouseJoint.h

@@ -95,6 +95,9 @@ public:
 	 **/
 	float getDampingRatio() const;
 
+	virtual Body *getBodyA() const;
+	virtual Body *getBodyB() const;
+
 private:
 	// The Box2D MouseJoint object.
 	b2MouseJoint *joint;