Javafx rendering glitch in jre 1.8.0_60

I have a javaFX 8 application that works fine in jre 1.8.0_45, but today a user came to me with a problem. After some investigation, I realized that this was due to its recent release of jre, in particular 1,8,0_60. I read the GIS shapefile and drew several paths to the group (for example, 30,000 or more) in my version, it was a little slower, but it worked fine. In the latest version, the image turned out to be distorted. Paths that go out of place and fail in pieces.

correct image generated in jre 1.8.0_45

distorted image generated in jre 1.8.0_60

So, I decided to make a small test application to separate the problem from everything that I could do. At the same time, I learned that the problem is not only in drawing outlines in a group, but also in drawing on canvas. Also, if I manage to redraw the screen, the image will look normal. For example, I have a checkbox associated with the visible property of the group containing the paths, so if I set it to false and then true, it takes some time to draw a scene, but then it looks fine. The test application is very simple, if you click the button, you create a canvas with some 10px10p squares, if you click another, you will create more squares and thus the display will fail.

package gisUI; import javafx.application.Application; import javafx.application.Platform; import javafx.scene.Group; import javafx.scene.Node; import javafx.scene.Scene; import javafx.scene.canvas.Canvas; import javafx.scene.canvas.GraphicsContext; import javafx.scene.control.Button; import javafx.scene.layout.HBox; import javafx.scene.layout.Pane; import javafx.scene.layout.VBox; import javafx.scene.paint.Color; import javafx.scene.paint.Paint; import javafx.scene.shape.LineTo; import javafx.scene.shape.MoveTo; import javafx.scene.shape.Path; import javafx.stage.Stage; public class Path2DTestApplication extends Application { private static final int WIDTH = 10; Group content = new Group(); @Override public void start(Stage stage) throws Exception { stage.setTitle("JavaFX 1.8.0_60 rendering test"); Button button = new Button("Canvas 100 x 30"); button.setOnAction(a->doGenerateCanvas(100,30)); Button button2 = new Button("Canvas 100 x 400"); button2.setOnAction(a->doGenerateCanvas(100,400)); Button button3 = new Button("Paths 100 x 30"); button3.setOnAction(a->doGeneratePaths(100,30)); VBox vBox = new VBox(); vBox.getChildren().addAll(new HBox(button,button2,button3),content); Group root = new Group(); root.getChildren().add(vBox); Scene scene = new Scene(root,80*WIDTH,60*WIDTH);//, 1500, 800);//, Color.White); stage.setScene(scene); stage.show(); } private void doGeneratePaths(int maxX,int maxY) { Pane paths = new Pane(); content.getChildren().clear(); Platform.runLater(()->{ for(int i = 0;i<maxX;i++){ for(int j=0;j<maxY;j++){ paths.getChildren().add(getPath(i,j)); } } content.getChildren().add(paths); }); } private void doGenerateCanvas(int maxX,int maxY) { content.getChildren().clear(); Platform.runLater(()->{ Canvas canvas = new Canvas(maxX*WIDTH, maxY*WIDTH); GraphicsContext gc = canvas.getGraphicsContext2D(); int counter =0; for(int i = 0;i<maxX;i++){ for(int j=0;j<maxY;j++){ gc.setFill(Color. rgb(255,(int) (Math.random()*255),191)); double[] xCoords = new double[]{i*WIDTH, (i+1)*WIDTH, (i+1)*WIDTH, i*WIDTH}; double[] yCoords = new double[]{j*WIDTH,(j)*WIDTH,(j+1)*WIDTH,(j+1)*WIDTH}; gc.fillPolygon(xCoords,yCoords,xCoords.length); counter++; } } System.out.println(counter +" polygons added"); content.getChildren().add(canvas); }); } protected Node getPath(int i,int j) { Path path = new Path(); path.getElements().add(new MoveTo(i*WIDTH, j*WIDTH)); path.getElements().add(new LineTo((i+1)*WIDTH, j*WIDTH)); path.getElements().add(new LineTo((i+1)*WIDTH, (j+1)*WIDTH)); path.getElements().add(new LineTo(i*WIDTH, (j+1)*WIDTH)); path.getElements().add(new LineTo(i*WIDTH, j*WIDTH)); Paint currentColor =Color. rgb(255,(int) (Math.random()*255),191); path.setFill(currentColor); path.setStrokeWidth(0.1); return path; } public static void main(String[] args) { Application.launch(Path2DTestApplication.class, args); } } 

Test 1: press the "Canvas 100 x 30" button, 3000 squares are typed correctly and quickly

Test 2: click the “Canvas 100 x 400” button, 40,000 squares showing the failure are shown.

Test 3: click the “Canvas 100 x 400” button, 40,000 squares are drawn correctly and quickly.

Test 4: click the "100 x 30 Ways" button, 3000 squares are displayed showing the glitch.

Test 5: press the “100 x 30 Ways” button again, 3000 squares are typed.

This is my first question for stakoverflow, sorry if I was not clear enough.

If anyone knows if this is a jre bug or there are some problems with my code, I would be grateful. Any workarounds would also be helpful. Tks !!

+6
source share
1 answer

I played with this on my MacBook Pro (OS X 10.9.5). It has its own 2880x1800 Retina LCD, with the included Thunderbolt 2560x1440 LCD. Note that the internal pixel resolution is different from these two displays.

When I run the code, I had no problems with any kind of canvas rendering. When I first started the “Paths” option or when switching from the “canvas” to “paths”, I saw playback problems similar to those that you describe, but only if the application was displayed on the lightning rod display. When switching to the Retina display, everything worked fine.

So the problem is with the equipment. This is clearly a mistake, and you should report it as indicated in the comment, but as a workaround, you can switch to software rendering using the system property -Dprism.order=sw from the command line:

 java -Dprism.order=sw gisUI.Path2DTestApplication 

This removed all rendering errors on my system. You should be aware that this can affect performance.

+2
source

All Articles