-
Bug
-
Resolution: Fixed
-
P3
-
jfx11, 8u60, jfx15
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8261588 | 8u301 | Kumar Abhishek | P3 | Resolved | Fixed | b01 |
ADDITIONAL SYSTEM INFORMATION :
Reproduced at least on Windows 10 with Oracle JDK 8u271, but it probably affects other JDK's as well.
A DESCRIPTION OF THE PROBLEM :
See attached code to reproduce. It creates a single Image, retrieves a pixel reader and reads the same pixel twice.
The issue seems to lie in com.sun.prism.Image#getPixelAccessor:
{code}
private Accessor<?> getPixelAccessor() {
if (pixelaccessor == null) {
// ... Initializes pixelAccessor
}
if (pixelaccessor != null && pixelScale != 1.0f) {
pixelaccessor = new ScaledAccessor<>(pixelaccessor, pixelScale);
}
return pixelaccessor;
}
{code}
Note the positioning of the second if-case, which should be located *inside* the first if-case.
With this position, the pixelAccessor will be wrapped in an additional ScaledAccessor every time getPixelAccessor is called, resulting in incorrect readings on every call after the first one.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the attached code.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Both calls to #getColor work.
ACTUAL -
The second #getColor throws an OutOfBoundsException, because the Image has applied the scale twice.
---------- BEGIN SOURCE ----------
package test;
import javafx.application.Application;
import javafx.scene.image.Image;
import javafx.scene.image.PixelReader;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
try {
Image image = new Image("https://static.wikia.nocookie.net/starwars/images/1/1e/Chewbacca-Fathead.png/revision/latest/scale-to-width-down/1000?cb=20161108052810");
PixelReader pixelReader = image.getPixelReader();
System.out.println(pixelReader.getColor((int) image.getWidth() - 1, (int) image.getHeight() - 1));
System.out.println(pixelReader.getColor((int) image.getWidth() - 1, (int) image.getHeight() - 1)); // throws OutOfBoundsException
} catch (Throwable e) {
e.printStackTrace();
}
System.exit(0);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Recreate the image each time you need it.
FREQUENCY : always
Reproduced at least on Windows 10 with Oracle JDK 8u271, but it probably affects other JDK's as well.
A DESCRIPTION OF THE PROBLEM :
See attached code to reproduce. It creates a single Image, retrieves a pixel reader and reads the same pixel twice.
The issue seems to lie in com.sun.prism.Image#getPixelAccessor:
{code}
private Accessor<?> getPixelAccessor() {
if (pixelaccessor == null) {
// ... Initializes pixelAccessor
}
if (pixelaccessor != null && pixelScale != 1.0f) {
pixelaccessor = new ScaledAccessor<>(pixelaccessor, pixelScale);
}
return pixelaccessor;
}
{code}
Note the positioning of the second if-case, which should be located *inside* the first if-case.
With this position, the pixelAccessor will be wrapped in an additional ScaledAccessor every time getPixelAccessor is called, resulting in incorrect readings on every call after the first one.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the attached code.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Both calls to #getColor work.
ACTUAL -
The second #getColor throws an OutOfBoundsException, because the Image has applied the scale twice.
---------- BEGIN SOURCE ----------
package test;
import javafx.application.Application;
import javafx.scene.image.Image;
import javafx.scene.image.PixelReader;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
try {
Image image = new Image("https://static.wikia.nocookie.net/starwars/images/1/1e/Chewbacca-Fathead.png/revision/latest/scale-to-width-down/1000?cb=20161108052810");
PixelReader pixelReader = image.getPixelReader();
System.out.println(pixelReader.getColor((int) image.getWidth() - 1, (int) image.getHeight() - 1));
System.out.println(pixelReader.getColor((int) image.getWidth() - 1, (int) image.getHeight() - 1)); // throws OutOfBoundsException
} catch (Throwable e) {
e.printStackTrace();
}
System.exit(0);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Recreate the image each time you need it.
FREQUENCY : always
- backported by
-
JDK-8261588 getColor throws IOOBE when PixelReader reads the same pixel twice
- Resolved