jMonkeyEngine / sdk

The jMonkeyEngine3 Software Development Kit based on Netbeans
BSD 3-Clause "New" or "Revised" License
316 stars 103 forks source link

NPE when the VehicleWheel node is selected + broken SDK #568

Closed capdevon closed 9 months ago

capdevon commented 9 months ago

NPE when the VehicleWheel node is selected in the scene element view tree. If you try to close and re-open the j3o model afterwards, the model view will always be completely black and you will have to restart the SDK.

image

Stacktrace:

java.lang.NullPointerException: Cannot invoke "org.openide.nodes.Node$Property.getName()" because "p" is null
    at org.openide.nodes.Sheet$Set.put(Sheet.java:294)
    at com.jme3.gde.core.sceneexplorer.nodes.JmeVehicleWheel.createSheet(JmeVehicleWheel.java:98)
    at org.openide.nodes.AbstractNode.getSheet(AbstractNode.java:416)
    at org.openide.nodes.AbstractNode.getPropertySets(AbstractNode.java:432)
    at com.jme3.gde.core.sceneexplorer.nodes.AbstractSceneExplorerNode.syncSceneData(AbstractSceneExplorerNode.java:280)
    at com.jme3.gde.core.scene.NodeSyncAppState.update(NodeSyncAppState.java:77)
    at com.jme3.app.state.AppStateManager.update(AppStateManager.java:371)
    at com.jme3.gde.core.scene.SceneApplication.update(SceneApplication.java:309)
    at com.jme3.system.awt.AwtPanelsContext.updateInThread(AwtPanelsContext.java:237)
    at com.jme3.system.awt.AwtPanelsContext.access$200(AwtPanelsContext.java:46)
    at com.jme3.system.awt.AwtPanelsContext$AwtPanelsListener.update(AwtPanelsContext.java:80)
    at com.jme3.system.lwjgl.LwjglOffscreenBuffer.runLoop(LwjglOffscreenBuffer.java:126)
    at com.jme3.system.lwjgl.LwjglOffscreenBuffer.run(LwjglOffscreenBuffer.java:160)
    at java.base/java.lang.Thread.run(Thread.java:1589)
java.lang.NullPointerException
neph1 commented 9 months ago

The class is performing some reflection on the VehicleWheel class. A particular method for getAxle exists, but it takes a Vector3f. I assume there used to be one that didn't, but somehow Minie works differently. Is it safe to just remove this (getAxle), or should it be handled differently?

The code in question: set.put(makeProperty(obj, Vector3f.class, "getAxle", "Axis"));

I've checked the other methods that the class calls (JmeVehicleWheel), and they still exist in VehicleWheel.

Edit: Some extra context: What this method does is create the "properties" panel with editable fields.

Edit: On closer inspection, getDirection also uses the same pattern.

Edit 3: Nevermind, I found netbeans has some helper methods for this use case. Will fix.

@stephengold Can you shed some light on this? (Sorry for ping)

stephengold commented 9 months ago

In jme3-jbullet, VehicleWheel.getAxle() takes no argument and returns a reference to the internal vector. Returning internal vectors is a common JME practice that looks very efficient but often leads to bugs.

In Minie I long ago changed VehicleWheel.getAxle() to copy the value of the vector. The Minie version requires a storeResult argument, which may be null. I made dozens of similar changes, but in many cases I left a no-arg version in place with a javadoc comment that the version is "for compatibility"---even though the Minie version doesn't behave exactly like the jme3-jbullet version.

neph1 commented 9 months ago

wheels

I spent some time making a wrapper but it didn't work out. So I've just removed them. They were just getters anyway and doesn't make sense to have in properties?