Skip to content

Commit 122afdf

Browse files
committed
FX: Prevent matrix stack overflow
Matrix stack could overflow in a very special case when beginShape() was called while strokeWeight=1 and then strokeWeight was changed before endShape(). This PR makes sure matrix is popped correctly even when user changes strokeWeight in the beginShape()/endShape() block. Decided to bug user only when necessary and not show warining when user changes strokeWeight in the beginShape()/endShape() block, same as in JAVA2D. Otherwise we could add checks for all the other things which are mentioned in the docs, but it would be hell to maintain and use. Fixes #4206
1 parent 5c219a3 commit 122afdf

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

core/src/processing/javafx/PGraphicsFX2D.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public class PGraphicsFX2D extends PGraphics {
6464
Path2D workPath = new Path2D();
6565
Path2D auxPath = new Path2D();
6666
boolean openContour;
67+
boolean adjustedForThinLines;
6768
/// break the shape at the next vertex (next vertex() call is a moveto())
6869
boolean breakShape;
6970

@@ -214,7 +215,7 @@ public void beginShape(int kind) {
214215
flushPixels();
215216

216217
if (drawingThinLines()) {
217-
pushMatrix();
218+
adjustedForThinLines = true;
218219
translate(0.5f, 0.5f);
219220
}
220221
}
@@ -420,8 +421,9 @@ public void endShape(int mode) {
420421
}
421422
}
422423
shape = 0;
423-
if (drawingThinLines()) {
424-
popMatrix();
424+
if (adjustedForThinLines) {
425+
adjustedForThinLines = false;
426+
translate(-0.5f, -0.5f);
425427
}
426428
loaded = false;
427429
}

0 commit comments

Comments
 (0)