danalizieors
danalizieors

Reputation: 41

Strange behavior using a variable in a JavaFX application

I am writing a very basic 3D modelling program. I've used LWJGL to render my objects and JavaFX to provide an user interface in a separate window, new thread.

As I saw JavaFX likes to take control over the application, but in my case this was not an option. I tried to pass my already created scene graph to the JavaFX controller class, but I didn't find a way doing this properly.

It's seems to be impossible to pass anything from outside into the main JavaFX class. The start method loads the layout from an FXML file with reflection magic, but this method is called in the constructor, therefore variables are not initialized. Defining a new constructor with parameters throws an exception (class cannot be initialized).

After struggling many hours, I gave up, I've decided to create a new scene graph in the JavaFX controller and created a getter method to it.

public class Toolbox extends Application implements Runnable {

    private ToolboxLogic logic = new ToolboxLogic(); //controller, the scene graph is instantiated

    ...

    public SceneGraph getSceneGraph() {
        return logic.sceneGraph; // returns the scene graph
    }
}

Not a beautiful solution, but it shall work, I said. But it doesn't. I tried to load a file in two locations:

If I load a file from the renderer, my objects show up on the screen, but I cannot navigate with the buttons, only the root node appears in the scene graph.

If I load a file from the user interface, I can navigate on the tree, but it doesn't show up in the renderer.

It seems like here

return logic.sceneGraph;

Java would have done a deep copy instead of returning a pointer, and each part of my program is working with its own version of the scene graph.

What is a problem, and how can I make it work properly?

Thank you!

Upvotes: 0

Views: 71

Answers (1)

danalizieors
danalizieors

Reputation: 41

OK, I got it working by setting the scene graph static. Strange! Now, I'm really curious, why it behaves like this.

Upvotes: 0

Related Questions