Skip to content

Commit 97d8ebf

Browse files
committed
Fix IllegalArgumentException caused by null arrays
1 parent e936019 commit 97d8ebf

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/main/java/org/spout/physics/engine/DynamicsWorld.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,16 @@ public DynamicsWorld(Vector3 gravity, float timeStep) {
116116
mTimer = new Timer(timeStep);
117117
mGravity = gravity;
118118
mIsGravityEnabled = true;
119-
mConstrainedLinearVelocities = null;
120-
mConstrainedAngularVelocities = null;
119+
Vector3[] empty = new Vector3[0];
120+
mConstrainedLinearVelocities = empty;
121+
mConstrainedAngularVelocities = empty;
121122
mContactSolver = new ContactSolver(mMapBodyToConstrainedVelocityIndex);
122123
mConstraintSolver = new ConstraintSolver(mConstrainedPositions, mConstrainedOrientations, mMapBodyToConstrainedVelocityIndex);
123124
mNbVelocitySolverIterations = ReactDefaults.DEFAULT_VELOCITY_SOLVER_NB_ITERATIONS;
124125
mNbPositionSolverIterations = ReactDefaults.DEFAULT_POSITION_SOLVER_NB_ITERATIONS;
125126
mIsSleepingEnabled = ReactDefaults.SLEEPING_ENABLED;
126-
mSplitLinearVelocities = null;
127-
mSplitAngularVelocities = null;
127+
mSplitLinearVelocities = empty;
128+
mSplitAngularVelocities = empty;
128129
mNbIslands = 0;
129130
mNbIslandsCapacity = 0;
130131
mIslands = null;

src/test/java/org/spout/physics/DynamicsWorldTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ public class DynamicsWorldTest {
4848
public void test() throws InterruptedException {
4949
final float timeStep = ReactDefaults.DEFAULT_TIMESTEP;
5050
final DynamicsWorld world = new DynamicsWorld(new Vector3(0, -9.81f, 0), timeStep);
51+
world.setEventListener(new TestListener());
52+
world.start();
53+
Thread.sleep(200);
54+
// We want to do one update with no bodies
55+
world.update();
56+
world.stop();
5157
final BoxShape floorShape = new BoxShape(new Vector3(10, 0.5f, 10));
5258
final Transform floorTransform = new Transform(new Vector3(0, 0, 0), Quaternion.identity());
5359
final Matrix3x3 floorInertia = new Matrix3x3();
@@ -63,7 +69,6 @@ public void test() throws InterruptedException {
6369
final RigidBody box = world.createRigidBody(boxTransform, boxMass, boxInertia, boxShape);
6470
final int stepCount = Math.round((1 / timeStep) * RUN_TIME);
6571
final int sleepTime = Math.round(timeStep * 1000);
66-
world.setEventListener(new TestListener());
6772
world.start();
6873
for (int i = 0; i < stepCount; i++) {
6974
final long start = System.nanoTime();

0 commit comments

Comments
 (0)