Describe the bug
When I spam jump and crouch so much on my game, an error, "java.lang.ArrayIndexOutOfBoundsException: index 100 out of bounds for length 100," occurs. But a while after the first initialization of the game, when I spam the buttons and controls again, the exception will not happen. A particular scenario is when I move left or right before jumping and crouching; the exception will not occur. Here is the complete error stack trace.
To Reproduce
Steps to reproduce the behavior:
- Initialize or compile and run the game
- Spam crouch or jump
- The error occurs
Expected behavior
I expect no crash will happen just by spamming crouching and jumping.
Runtime info(please complete the following information):
Windows 11
Attach log associated with the bug (can be found in "logs/")
java.lang.ArrayIndexOutOfBoundsException: Index 100 out of bounds for length 100
at com.almasb.fxgl.entity@17.3/com.almasb.fxgl.physics.box2d.pooling.OrderedStack.pop(OrderedStack.java:34)
at com.almasb.fxgl.entity@17.3/com.almasb.fxgl.physics.box2d.pooling.DefaultWorldPool.popRot(DefaultWorldPool.java:232)
at com.almasb.fxgl.entity@17.3/com.almasb.fxgl.physics.box2d.dynamics.joints.RopeJoint.solvePositionConstraints(RopeJoint.java:195)
at com.almasb.fxgl.entity@17.3/com.almasb.fxgl.physics.box2d.dynamics.Island.solve(Island.java:326)
at com.almasb.fxgl.entity@17.3/com.almasb.fxgl.physics.box2d.dynamics.World.solve(World.java:423)
at com.almasb.fxgl.entity@17.3/com.almasb.fxgl.physics.box2d.dynamics.World.step(World.java:279)
at com.almasb.fxgl.entity@17.3/com.almasb.fxgl.physics.PhysicsWorld.onUpdate(PhysicsWorld.java:176)
at com.almasb.fxgl.all@17.3/com.almasb.fxgl.app.scene.GameScene.step(GameScene.kt:229)
at com.almasb.fxgl.all@17.3/com.almasb.fxgl.app.scene.GameScene.onUpdate(GameScene.kt:224)
at com.almasb.fxgl.scene@17.3/com.almasb.fxgl.scene.Scene.update(Scene.kt:105)
at com.almasb.fxgl.all@17.3/com.almasb.fxgl.app.MainWindow$update$1.invoke(MainWindow.kt:115)
at com.almasb.fxgl.all@17.3/com.almasb.fxgl.app.MainWindow$update$1.invoke(MainWindow.kt:115)
at com.almasb.fxgl.core@17.3/com.almasb.fxgl.core.fsm.StateMachine.runOnActiveStates(StateMachine.kt:69)
at com.almasb.fxgl.all@17.3/com.almasb.fxgl.app.MainWindow.update(MainWindow.kt:115)
at com.almasb.fxgl.all@17.3/com.almasb.fxgl.app.FXGLApplication$GameApplicationService.onUpdate(FXGLApplication.kt:426)
at com.almasb.fxgl.all@17.3/com.almasb.fxgl.app.Engine.loop(Engine.kt:134)
at com.almasb.fxgl.all@17.3/com.almasb.fxgl.app.Engine.access$loop(Engine.kt:24)
at com.almasb.fxgl.all@17.3/com.almasb.fxgl.app.Engine$loop$1.invoke(Engine.kt:28)
at com.almasb.fxgl.all@17.3/com.almasb.fxgl.app.Engine$loop$1.invoke(Engine.kt:28)
at com.almasb.fxgl.all@17.3/com.almasb.fxgl.app.LoopRunner.frame(LoopRunner.kt:103)
at com.almasb.fxgl.all@17.3/com.almasb.fxgl.app.LoopRunner.access$frame(LoopRunner.kt:23)
at com.almasb.fxgl.all@17.3/com.almasb.fxgl.app.LoopRunner$impl$2$1.onTick(LoopRunner.kt:57)
at com.almasb.fxgl.all@17.3/com.almasb.fxgl.app.AnimationTimerLoop$timer$1.handle(LoopRunner.kt:137)
at javafx.graphics/javafx.animation.AnimationTimer$AnimationTimerReceiver.lambda$handle$0(AnimationTimer.java:58)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
at javafx.graphics/javafx.animation.AnimationTimer$AnimationTimerReceiver.handle(AnimationTimer.java:57)
at javafx.graphics/com.sun.scenario.animation.AbstractPrimaryTimer.timePulseImpl(AbstractPrimaryTimer.java:356)
at javafx.graphics/com.sun.scenario.animation.AbstractPrimaryTimer$MainLoop.run(AbstractPrimaryTimer.java:266)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:571)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:555)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.pulseFromQueue(QuantumToolkit.java:548)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.lambda$runToolkit$11(QuantumToolkit.java:353)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
at java.base/java.lang.Thread.run(Thread.java:1575)
Additional context / possible fixes
I am using rope joint to join two players together, below are the codes that possibly propagated the error.
initPhysics() - This initialized the rope joint def
protected void initPhysics() {
super.initPhysics();
var player1 = getPlayer1();
var physics1 = player1.getComponent(PhysicsComponent.class);
var player2 = getPlayer2();
var physics2 = player2.getComponent(PhysicsComponent.class);
Body bodyA = physics1.getBody();
Body bodyB = physics2.getBody();
FXGL.runOnce(() -> {
RopeJointDef ropeDef = new RopeJointDef();
ropeDef.setBodyA(bodyA);
ropeDef.setBodyB(bodyB);
ropeDef.localAnchorA.set(0, 0);
ropeDef.localAnchorB.set(0, 0);
ropeDef.maxLength = 3.0f;
ropeDef.setBodyCollisionAllowed(false);
FXGL.getPhysicsWorld().getJBox2DWorld().createJoint(ropeDef);
}, Duration.seconds(0.1));
}
Below is the on the input for the jump
FXGL.getInput().addAction(new UserAction ("Jump1") {
@Override
protected void onAction() {
getControlP1().jump();
}
}, KeyCode.W);
public void jump() {
if (!physics.isOnGround()) {
return;
}
physics.setVelocityY(-Constants.JUMP_FORCE);
state.changeState(JUMP);
}
Below is the code of the crouch
FXGL.getInput().addAction(new UserAction("Crouch1") {
@Override
protected void onAction() {
getControlP1().crouch();
}
@Override
protected void onActionEnd() {
getControlP1().stand();
}
}, KeyCode.S);
public void crouch() {
if (physics.isOnGround() && state.isIn(STAND, WALK)) {
physics.setVelocityX(0);
state.changeState(CROUCH);
if(physics.getBody().getType() != BodyType.STATIC) {
physics.getBody().setType(BodyType.STATIC);
}
}
}
public void stand() {
state.changeState(STAND);
if(physics.getBody().getType() == BodyType.STATIC) {
physics.getBody().setType(BodyType.DYNAMIC);
}
}
When I crouch, I changed the body of the entity into a STATIC since I don't want no movements, then revert it back to DYNAMIC to freely move it again.
Describe the bug
When I spam jump and crouch so much on my game, an error, "java.lang.ArrayIndexOutOfBoundsException: index 100 out of bounds for length 100," occurs. But a while after the first initialization of the game, when I spam the buttons and controls again, the exception will not happen. A particular scenario is when I move left or right before jumping and crouching; the exception will not occur. Here is the complete error stack trace.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
I expect no crash will happen just by spamming crouching and jumping.
Runtime info(please complete the following information):
Windows 11
Attach log associated with the bug (can be found in "logs/")
Additional context / possible fixes
I am using rope joint to join two players together, below are the codes that possibly propagated the error.
initPhysics() - This initialized the rope joint def
Below is the on the input for the jump
Below is the code of the crouch
When I crouch, I changed the body of the entity into a STATIC since I don't want no movements, then revert it back to DYNAMIC to freely move it again.