jMonkeyEngine / jMonkeyEngine/jmonkeyengine

Spatial.clone breaks rigidbodies

Open
#797 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Contribution welcome Physics
Dominant language
Java
Stars
4.3k
Forks
1.2k
Avg merge
4d 7h
Merged PRs (30d)
14

Description

It seems that the user object is never set for cloned rigidbodies.

Test code:

import com.jme3.app.SimpleApplication;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.material.Material;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;

public class Test  extends SimpleApplication{
    public static void main(String[] args) {
        Test t=new Test();
        t.setShowSettings(false);
        t.start();
    }   

    Geometry cloned;
    Geometry original;
    float DELAY=2.f;

    @Override
    public void simpleInitApp() {
        BulletAppState bas=new BulletAppState();
        stateManager.attach(bas);        
        Box b=new Box(10,10,10);
        Material mat=new Material(assetManager,"Common/MatDefs/Misc/Unshaded.j3md");
        

        original=new Geometry("Test",b);
        original.setMaterial(mat);
        original.addControl(new RigidBodyControl(0));
        rootNode.attachChild(original);
        bas.getPhysicsSpace().addAll(original);
  
        cloned=original.clone();
        bas.getPhysicsSpace().addAll(cloned);
        rootNode.attachChild(cloned);
    
    
    }

    @Override
    public void simpleUpdate(float tpf){
        DELAY-=tpf;
        if(DELAY<=0){
            DELAY=2.f;
            if(cloned.getControl(RigidBodyControl.class).getUserObject()==null){
                System.out.println("/!\\ Cloned RigidBody has null user object");
            }else{
                System.out.println("Everything is fine");
            }
        }
    }
}

Full gradle project: http://bit.ly/2APrAGN

$ gradle execute
[...]
/!\ Cloned RigidBody has null user object
/!\ Cloned RigidBody has null user object
/!\ Cloned RigidBody has null user object
/!\ Cloned RigidBody has null user object

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the supplied Gradle project with gradle execute and tracing Spatial.clone together with RigidBodyControl cloning. Verify how the cloned rigidbody's user object is initialized, then rerun the reproduction and confirm it no longer prints the null-user warning.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
game-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.