Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPE at javafx.scene.text.Text.getSpanBounds(Text.java:292) #15

Closed
miho opened this issue Feb 28, 2014 · 13 comments
Closed

NPE at javafx.scene.text.Text.getSpanBounds(Text.java:292) #15

miho opened this issue Feb 28, 2014 · 13 comments

Comments

@miho
Copy link

miho commented Feb 28, 2014

Just tried to use the CodeArea inside a JFXtras-labs 8 window control. Unfortunately I get the following error:

Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
    at javafx.scene.text.Text.getSpanBounds(Text.java:292)
    at javafx.scene.text.Text.impl_computeGeomBounds(Text.java:1146)
    at javafx.scene.Node.updateGeomBounds(Node.java:3526)

JavaFX TextArea and Text nodes do work.

The error does not occur if I prevent layout calls via setManaged(false).

What I do exactly:

CodeArea textArea = new CodeArea();
textArea.replaceText("my code");

Window w = new Window("CodeEditor");
w.setPreferredSize(400,300);

// content pane is a regular stack pane
w.getContentPane().getChildren().add(textArea);

rootPane.getChildren().add(w);

I'm testing on OS X, JDK 8-b129 and the CodeAreaFX from commit b8846ca3e1fba8e4829ee3d015b305b2bf99380c

@TomasMikula
Copy link
Member

Can you please post the full code, so that I can try it out? For example, I don't know where rootPane in your example comes from. Can you also point me to the JFXtras-labs JAR you are using?

@miho
Copy link
Author

miho commented Feb 28, 2014

I'll setup a small project to demonstrate the issue.

@miho
Copy link
Author

miho commented Mar 3, 2014

Seems to be related to the ScalableContentPane. I haven't had any issues with applying scale transformations to controls so far.

How To Reproduce:

Before running it, call the fetchDeps task which downloads CodeAreaFX.

Use the withScalableContentPane toggle to change scene setup (with or without ScalableContentPane).

Here's the code: https://gist.github.com/miho/9322527
Complete Project: https://drive.google.com/file/d/0B5SD3655oxUQWVdaaDhRdzlLYzA/edit?usp=sharing

Can you reproduce it?

@TomasMikula
Copy link
Member

Thanks for the sample code. Seems to be a TextFlow problem. This is how I changed your code (leaving out CodeArea altogether):

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.text.Text;
import javafx.scene.text.TextFlow;
import javafx.stage.Stage;
import jfxtras.labs.scene.control.window.CloseIcon;
import jfxtras.labs.scene.control.window.Window;
import jfxtras.labs.scene.layout.ScalableContentPane;

public class Main extends Application {

    /**
     * The main() method is ignored in correctly deployed JavaFX application.
     * main() serves only as fallback in case the application can not be
     * launched through deployment artifacts, e.g., in IDEs with limited FX
     * support. NetBeans ignores main().
     *
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {

        // indicates whether to use a scalable content pane
        boolean withScalableContentPane = true;

        // setup scene
        Pane canvas;
        Scene scene;
        if (withScalableContentPane) {
            ScalableContentPane root = new ScalableContentPane();
            canvas = root.getContentPane();
            scene = new Scene(root, 800, 600);
        } else {
            canvas = new Pane();
            scene = new Scene(canvas, 800, 600);
        }

        // add a window that contains a TextFlow
        TextFlow textFlow = new TextFlow(new Text("The Code"));
        Window w = new Window("Editor");
        w.getLeftIcons().add(new CloseIcon(w));
        w.setPrefSize(400, 300);
        w.getContentPane().getChildren().add(textFlow);
        canvas.getChildren().add(w);

        // show the stage
        primaryStage.setTitle("Demo!");
        primaryStage.setScene(scene);
        primaryStage.show();

    }
}

When I run this, I actually get an infinite loop of exceptions.

Another observation I made is that the combination of ScalableContentPane and Window is required to reproduce the bug. Adding the TextFlow (or CodeArea) directly to canvas works.

I'm going to close this. When the problem with TextFlow is fixed and the problem with CodeArea does not go away, please reopen.

@miho
Copy link
Author

miho commented Mar 4, 2014

Thanks for your response!

I found a workaround for the TextFlow case by invoking layout() after instantiaton:

    TextFlow codeArea = new TextFlow(new Text("The Code"));
    codeArea.layout(); // fixes the problem

Unfortunately this does not work for CodeArea.

@TomasMikula
Copy link
Member

I reported this to OpenJFX: RT-36130.

@miho
Copy link
Author

miho commented Mar 8, 2014

Thanks!

@miho
Copy link
Author

miho commented Aug 23, 2014

Unfortunately, the CodeArea still does not work with the ScalableContentPane. With 8u20 the error is different:

    Exception in thread "JavaFX Application Thread" java.lang.ArrayIndexOutOfBoundsException: -1
    at java.util.ArrayList.elementData(ArrayList.java:418)
    at java.util.ArrayList.get(ArrayList.java:431)
    at com.sun.javafx.collections.ObservableListWrapper.get(ObservableListWrapper.java:89)
    at com.sun.javafx.collections.VetoableListDecorator.get(VetoableListDecorator.java:306)
    at javafx.scene.Parent.updateCachedBounds(Parent.java:1579)
    at javafx.scene.Parent.recomputeBounds(Parent.java:1523)
    at javafx.scene.Parent.impl_computeGeomBounds(Parent.java:1374)
    at javafx.scene.layout.Region.impl_computeGeomBounds(Region.java:3022)
    at javafx.scene.Node.updateGeomBounds(Node.java:3552)
    at javafx.scene.Node.getGeomBounds(Node.java:3505)
    at javafx.scene.Node.getLocalBounds(Node.java:3453)
    at javafx.scene.Node.updateTxBounds(Node.java:3616)
    at javafx.scene.Node.getTransformedBounds(Node.java:3399)
    at javafx.scene.Parent.recomputeBounds(Parent.java:1510)
    at javafx.scene.Parent.impl_computeGeomBounds(Parent.java:1374)
    at javafx.scene.layout.Region.impl_computeGeomBounds(Region.java:3022)
    at javafx.scene.Node.updateGeomBounds(Node.java:3552)
    at javafx.scene.Node.getGeomBounds(Node.java:3505)

I'd love to use RichTextFX for my JavaOne Live Demos. Any ideas?

Note: it works with TextFlow

@TomasMikula
Copy link
Member

Is this with the latest 0.4.2 version?

@miho
Copy link
Author

miho commented Aug 23, 2014

0.4.2 and 1.0-SNAPSHOT

@TomasMikula
Copy link
Member

Hi Michael,

I did some digging and the following might be the cause of this exception, but certainly is a bug in JFXtras' Window.

Node.boundsInParentProperty's Javadoc says

Note that boundsInParent is automatically recomputed whenever the geometry of a node changes, or when any of the following the change: transforms ObservableList, translateX, translateY, layoutX, layoutY, scaleX, scaleY, or the rotate variable. For this reason, it is an error to bind any of these values in a node to an expression that depends upon this variable. For example, the x or y variables of a shape, or translateX, translateY should never be bound to boundsInParent for the purpose of positioning the node.

However, Window.java sets layoutX and layoutY from a boundsInParent listener, which is an error per the above Javadoc comment.

@miho
Copy link
Author

miho commented Aug 24, 2014

Thanks for this hint! Looks like we produce event garbage in the window control.

@miho
Copy link
Author

miho commented Aug 24, 2014

It works! Thanks again. Just in case anybody else is having this issue: use the window control from jfxtras-window instead of the one from jfxtras-labs. It does not have the issue mentioned by Tomas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants