JDK-8095612 : Snapshot of any node throws IllegalArgumentException while screen is locked
  • Type: Bug
  • Component: javafx
  • Sub-Component: graphics
  • Affected Version: 7u13,8
  • Priority: P4
  • Status: Resolved
  • Resolution: Duplicate
  • Submitted: 2013-09-10
  • Updated: 2015-06-12
  • Resolved: 2014-05-09
Related Reports
Blocks :  
Duplicate :  
Description
Here's some example code that won't work if the snapshot is taken while the screen is locked (and it was locked after application start) in both Java 7 and 8.
 
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.layout.BorderPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

public class SnapshotTester extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {

        final BorderPane borderPane = new BorderPane();
        final Rectangle rectangle = new Rectangle(20, 20, Color.BLUE);
        borderPane.setCenter(rectangle);
        Scene scene = new Scene(borderPane);
        primaryStage.setScene(scene);
        primaryStage.show();

        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(2000);
                    Platform.runLater(new Runnable() {
                        @Override
                        public void run() {
                            Image snapshot = rectangle.snapshot(null, null);
                            System.out.println("Snapshot taken: " + snapshot);
                        }
                    });
                } catch (InterruptedException ignored) {
                }
            }
        }).start();
    }

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

Steps to reproduce:

1) Start application

2) Lock screen as soon as window is shown

3) Unlock after two seconds


You'll get the following exception which is unfortunately not very expressive:


java.lang.IllegalArgumentException: Unrecognized image loader: null
at javafx.scene.image.WritableImage.loadTkImage(WritableImage.java:230)
at javafx.scene.image.WritableImage.access$000(WritableImage.java:44)
at javafx.scene.image.WritableImage$1.loadTkImage(WritableImage.java:49)
at javafx.scene.Scene.doSnapshot(Scene.java:1144)
at javafx.scene.Node.doSnapshot(Node.java:1632)
at javafx.scene.Node.snapshot(Node.java:1710)

Might be related to RT-30362
Comments
Resolved as a duplicate of RT-36571.
09-05-2014

With the fix for RT-36571 we can no longer get a lost surface so this bug does not happen any more. Verified with the latest build of 8u20 which includes the fix for RT-36571.
09-05-2014

We may be able to fix this when RT-36571 is implemented. Otherwise we will provide a more informative exception message.
11-04-2014