Skip to content

BlocksConfig.setShapeRegistry() doesn't update the chunk mesh generator. [version 1.5.1] #54

@Igrium

Description

@Igrium

At least, this is what I think is happening.

I'm adding a custom shape registry in simpleInitApp() after I initialize the blocks config:

BlocksConfig.initialize(assetManager);
BlocksConfig.getInstance().setChunkSize(new Vec3i(Chunk.WIDTH, Chunk.HEIGHT, Chunk.LENGTH));
		
meshRegistry = new MeshRegistry();
BlocksConfig.getInstance().setShapeRegistry(meshRegistry);

All that MeshRegistry does is override the get() method to patch into my custom system, which is tested to work:

@Override
public Shape get(String name) {
	System.out.println("Pulling from custom shape registry");
	try {
		return loadMesh(name);
	} catch (IOException e) {
		System.out.println("Cannot load mesh file "+name+". Falling back to JME Blocks shape registry.");
		return super.get(name);
	}
}

Yet, when I try to compile the chunk mesh, I get a NullPointerException tracing back to com.rvandoosselaer.blocks.FacesMeshGenerator.createNode(FacesMeshGenerator.java:59), which looking into the source code reveals to be:

// add the block mesh to the chunk mesh
Shape shape = shapeRegistry.get(block.getShape());
shape.add(blockLocation, chunk, mesh); <

What's interesting is that it's obviously calling shapeRegistry.get() and getting back null, but my test print statement, System.out.println("Pulling from custom shape registry");, is not firing. This leads me to conclude that the shapeRegistry variable inside FacesMeshGenerator is not getting updated when I call BlocksConfig.setShapeRegistry(), and the program is attempting to use a key belonging to my custom system on the default system, which would obviously return null.

The full source code the project in which the issue was found is at http://scaffoldeditor.org under the editor_rendering branch. Here's the full traceback. I'm running the whole JME program inside a Swing window, so it's rather long:

Compiling world...
Loading render world...
java.lang.NullPointerException
        at com.rvandoosselaer.blocks.FacesMeshGenerator.createNode(FacesMeshGenerator.java:59)
        at com.rvandoosselaer.blocks.Chunk.createNode(Chunk.java:163)
        at org.scaffoldeditor.editor.editor3d.test.Tester.test(Tester.java:43)
        at org.scaffoldeditor.editor.editor3d.EditorApp.runTestCode(EditorApp.java:190)
        at org.scaffoldeditor.editor.ui.EditorWindow.runTestCode(EditorWindow.java:442)
        at org.scaffoldeditor.editor.ui.EditorWindow$10.actionPerformed(EditorWindow.java:254)
        at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
        at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
        at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
        at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
        at javax.swing.AbstractButton.doClick(AbstractButton.java:376)
        at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:842)
        at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:886)
        at java.awt.Component.processMouseEvent(Component.java:6539)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
        at java.awt.Component.processEvent(Component.java:6304)
        at java.awt.Container.processEvent(Container.java:2239)
        at java.awt.Component.dispatchEventImpl(Component.java:4889)
        at java.awt.Container.dispatchEventImpl(Container.java:2297)
        at java.awt.Component.dispatchEvent(Component.java:4711)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4904)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4535)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4476)
        at java.awt.Container.dispatchEventImpl(Container.java:2283)
        at java.awt.Window.dispatchEventImpl(Window.java:2746)
        at java.awt.Component.dispatchEvent(Component.java:4711)
        at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:760)
        at java.awt.EventQueue.access$500(EventQueue.java:97)
        at java.awt.EventQueue$3.run(EventQueue.java:709)
        at java.awt.EventQueue$3.run(EventQueue.java:703)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
        at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:84)
        at java.awt.EventQueue$4.run(EventQueue.java:733)
        at java.awt.EventQueue$4.run(EventQueue.java:731)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:730)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
AL lib: (EE) alc_cleanup: 1 device not closed

Thank you for coming to my TED talk.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions