Weird restitution? Bug?

Hey,

according to the box2d manual a restitution of 1 should exactly reflect an object again. That means it will bounce and bounce and never get heigher?

I modified the hello-word example from the box2d example to the java-syntax and changed the restitution to 1. But my dynamic object gets heigher and heigher 🙁. Am I missing something here?

Code:
package de.transformice.engine.game;

import org.jbox2d.collision.shapes.PolygonShape;
import org.jbox2d.common.Vec2;
import org.jbox2d.dynamics.*;

public class EngineTest {

    public static void main(String[] args) {

        new EngineTest().controller();

    }

    private void controller() {
        Vec2 gravity = new Vec2(0.0f, -10.0f);

        boolean doSleep = true;
        World world = new World(gravity, doSleep);
        BodyDef groundBodyDef = new BodyDef();

        groundBodyDef.position.set(gravity);
        Body groundBody = world.createBody(groundBodyDef);

        PolygonShape groundBox = new PolygonShape();

        groundBox.setAsBox(50.0f, 10.0f);


        Fixture fixture = groundBody.createFixture(groundBox, 0.0f);
        fixture.m_restitution = 1f;

        System.out.println(fixture.m_restitution);

        BodyDef bodyDef = new BodyDef();

        bodyDef.type = BodyType.DYNAMIC;

        bodyDef.position.set(0.0f, 4.0f);

        Body body = world.createBody(bodyDef);
        PolygonShape dynamicBox = new PolygonShape();

        dynamicBox.setAsBox(1.0f, 1.0f);
        FixtureDef fixtureDef = new FixtureDef();

        fixtureDef.shape = dynamicBox;

        fixtureDef.density = 1.0f;

        fixtureDef.friction = 0.3f;

        body.createFixture(fixtureDef);
        float timeStep = 1.0f / 60.0f;
        int velocityIterations = 10;

        int positionIterations = 10;

        for (int i = 0; i < 6000; ++i) {
            world.step(timeStep, velocityIterations, positionIterations);
            Vec2 position = body.getPosition();
            float angle = body.getAngle();
            System.out.println(position.x + " " + position.y + " " + angle);
        }
    }
}



First line:
0.0 3.9972222 0.0
last line:
2.5020097E-6 11.339587 1.2851934E-4
This is usually caused by floating point calculation errors with the underlying system and its optimizations.

Original thread: https://box2d.org/forum/viewtopic.php?t=8207