Skip to content

Commit a548f35

Browse files
committed
Java2D images crash after being resized (processing#2113)
1 parent ebf7bda commit a548f35

2 files changed

Lines changed: 32 additions & 6 deletions

File tree

core/src/processing/core/PGraphicsJava2D.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,15 +1247,25 @@ protected void imageImpl(PImage who,
12471247
// Image not ready yet, or an error
12481248
if (who.width <= 0 || who.height <= 0) return;
12491249

1250-
if (getCache(who) == null) {
1250+
ImageCache cash = (ImageCache) getCache(who);
1251+
1252+
// Nuke the cache if the image was resized
1253+
if (cash != null) {
1254+
if (who.width != cash.image.getWidth() ||
1255+
who.height != cash.image.getHeight()) {
1256+
cash = null;
1257+
}
1258+
}
1259+
1260+
if (cash == null) {
12511261
//System.out.println("making new image cache");
1252-
this.setCache(who, new ImageCache(who));
1262+
cash = new ImageCache(who);
1263+
setCache(who, cash);
12531264
who.updatePixels(); // mark the whole thing for update
12541265
who.modified = true;
12551266
}
12561267

1257-
ImageCache cash = (ImageCache) getCache(who);
1258-
// if image previously was tinted, or the color changed
1268+
// If image previously was tinted, or the color changed
12591269
// or the image was tinted, and tint is now disabled
12601270
if ((tint && !cash.tinted) ||
12611271
(tint && (cash.tintedColor != tintColor)) ||
@@ -1273,8 +1283,8 @@ protected void imageImpl(PImage who,
12731283
(int) x1, (int) y1, (int) x2, (int) y2,
12741284
u1, v1, u2, v2, null);
12751285

1276-
// every few years I think "nah, Java2D couldn't possibly be that
1277-
// f*king slow, why are we doing this by hand? then comes the affirmation.
1286+
// Every few years I think "nah, Java2D couldn't possibly be that f*king
1287+
// slow, why are we doing this by hand?" then comes the affirmation:
12781288
// Composite oldComp = null;
12791289
// if (false && tint) {
12801290
// oldComp = g2.getComposite();

core/todo.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,29 @@ X http://stackoverflow.com/questions/10556875/list-of-unicode-characters-that-
1212
X http://stackoverflow.com/questions/3072152/what-is-unicode-character-2028-ls-line-separator-used-for
1313
X fix image transparency in PDF output
1414
X https://github.com/processing/processing/pull/2070
15+
X Java2D images crash after being resized
16+
X https://github.com/processing/processing/issues/2113
17+
18+
opengl
19+
X fix inconsistency with P2D and resetMatrix()
20+
X https://github.com/processing/processing/issues/2087
21+
X text rendering problems
22+
X https://github.com/processing/processing/issues/2109
23+
X textSize() not working properly in P2D
24+
X https://github.com/processing/processing/issues/2073
25+
X incorrectly applied transformations in retained mode
26+
X https://github.com/processing/processing/issues/2097
27+
X push/popStyle() causes color problems with P2D/P3D
28+
X https://github.com/processing/processing/issues/2102
1529

1630
_ Sort out blending differences with P2D/P3D
1731
_ https://github.com/processing/processing/issues/1844
1832
_ 'collector' class.. Dict that points to a list
1933
_ String as a key, int/float/string list as values
2034

2135
high
36+
_ custom DPI settings with PDF
37+
_ https://github.com/processing/processing/pull/2069
2238
_ loadPixels doesn't set alpha value for pixels on Java2D
2339
_ https://github.com/processing/processing/issues/2030
2440
_ blendMode(ADD) is broken with default renderer

0 commit comments

Comments
 (0)