2

I'm trying to write a simple FX8 image display program on the Raspberry Pi2 with only 64MB of GPU memory. This results in a NullPointer Exception at com.sun.prism.impl.BaseGraphics.drawTexture attempting to render the ImageView. This is with the packaged Oracle JDK8 (build 1.8.0-b132).

I was told on the Pi stackexchange that 128MB is the minimum GPU memory to use the OpenGL features, which doesn't seem unreasonable... but I don't think I'm doing anything fancy enough to need OpenGL.

Question

I'm new to JavaFX and the Pi, so maybe I'm headed in the wrong direction. I'm using Rasbian/X11, but am not tied to it. Does JavaFX8 have a mechanism that will allow me display a fullscreen image without using OpenGL?

MCVE:

My minimum demonstration is very straightforward: an AnchorView holding an ImageView, displaying a 29kB PNG (1847x1080).

package sample;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception
    {
        Image image = new Image("/Sponsor.png");
        ImageView imageview = new ImageView(image);
        AnchorPane root = new AnchorPane(imageview);
        Scene scene = new Scene(root, 400, 275);
        primaryStage.setScene(scene);
        imageview.setFitHeight(scene.getHeight());
        imageview.setFitWidth(scene.getWidth());
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

Stack trace

glGetError 0x505
java.lang.NullPointerException
    at com.sun.prism.impl.BaseGraphics.drawTexture(BaseGraphics.java:389)
    at com.sun.prism.impl.ps.BaseShaderGraphics.drawTexture(BaseShaderGraphics.java:139)
    at com.sun.prism.image.Coords.draw(Coords.java:46)
    at com.sun.prism.image.CompoundCoords.draw(CompoundCoords.java:94)
    at com.sun.javafx.sg.prism.NGImageView.renderContent(NGImageView.java:134)
    at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:2043)
    at com.sun.javafx.sg.prism.NGImageView.doRender(NGImageView.java:103)
    at com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1951)
    at com.sun.javafx.sg.prism.NGGroup.renderContent(NGGroup.java:225)
    at com.sun.javafx.sg.prism.NGRegion.renderContent(NGRegion.java:575)
    at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:2043)
    at com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1951)
    at com.sun.javafx.tk.quantum.ViewPainter.doPaint(ViewPainter.java:469)
    at com.sun.javafx.tk.quantum.ViewPainter.paintImpl(ViewPainter.java:324)
    at com.sun.javafx.tk.quantum.PresentingPainter.run(PresentingPainter.java:89)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
    at com.sun.javafx.tk.RenderJob.run(RenderJob.java:58)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(QuantumRenderer.java:129)
    at java.lang.Thread.run(Thread.java:744)
Autumn
  • 3,214
  • 1
  • 20
  • 35

1 Answers1

1

Yes, you should be able to do that. JavaFX can use the old Java2D API for mere software rendering. Normally it should do so only on Systems where no hardware acceleration is availlable. If there is, but it does not work properly, one should try to disable hardware acceleration by adding a command line option when starting the application:

-Dprism.order=j2d

Currently, it seems to be hard to find official documentation, but elsewhere on SO this is reported to work.

Robert Rohm
  • 331
  • 1
  • 7
  • 1
    Petr's answer to [How to disable or bypass Hardware Graphics Acceleration(Prism) in JavaFX](http://stackoverflow.com/questions/18754803/how-to-disable-or-bypass-hardware-graphics-accelerationprism-in-javafx), suggests "The j2d graphics pipeline is kind of deprecated in JavaFX 8, so it's better to use the software pipeline: `-Dprism.order=sw`". Also, I think Java2D may optionally use hardware acceleration, so setting to j2d may not completely disable hardware acceleration. As you note, none of these switches are officially documented or supported (but they should work anyway). – jewelsea Oct 28 '15 at 21:35
  • Thanks @jewelsea, these are both valid answers, and work correctly on my desktop environment. Neither work on the pi, however. The j2d pipeline throws a RTE with "Error initializing QuantumRenderer: no suitable pipeline found." Fair enough, it's deprecated. However, the sw pipeline throws a SIGSEGV. Will wait for comments on the pi exchange and then post a bug report to Oracle. – Autumn Oct 29 '15 at 00:16