From 82c772f17888d3cc73fbfa5ce66081c1b0d7369a Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Sun, 3 Sep 2017 08:36:23 -0400 Subject: [PATCH] Windows ignores setMinimumSize(), add workaround for #5052 --- core/src/processing/awt/PSurfaceAWT.java | 13 ++++++----- core/src/processing/javafx/PSurfaceFX.java | 18 +++++++++++---- core/src/processing/opengl/PSurfaceJOGL.java | 24 ++++++++++++++------ core/todo.txt | 6 ++++- todo.txt | 12 ++++++---- 5 files changed, 51 insertions(+), 22 deletions(-) diff --git a/core/src/processing/awt/PSurfaceAWT.java b/core/src/processing/awt/PSurfaceAWT.java index 360086142..4cf50e87f 100644 --- a/core/src/processing/awt/PSurfaceAWT.java +++ b/core/src/processing/awt/PSurfaceAWT.java @@ -945,14 +945,15 @@ public class PSurfaceAWT extends PSurfaceNone { // needs to resize the frame, which will resize the canvas, and so on... @Override public void setSize(int wide, int high) { - - //In Microsoft Windows, when the surface is set to resizable (surface.setResizable(true)), - //the height set by the user can become less than or equal to zero and program crashes - //when that occurs. This is a simple fix for that - //(issue: https://github.com/processing/processing/issues/5052) - if(high <= 0) { + // When the surface is set to resizable via surface.setResizable(true), + // a crash may occur if the user sets the window to size zero. + // https://github.com/processing/processing/issues/5052 + if (high <= 0) { high = 1; } + if (wide <= 0) { + wide = 1; + } // if (PApplet.DEBUG) { // //System.out.format("frame visible %b, setSize(%d, %d) %n", frame.isVisible(), wide, high); diff --git a/core/src/processing/javafx/PSurfaceFX.java b/core/src/processing/javafx/PSurfaceFX.java index 1e0d2ce02..1b1843955 100644 --- a/core/src/processing/javafx/PSurfaceFX.java +++ b/core/src/processing/javafx/PSurfaceFX.java @@ -616,14 +616,24 @@ public class PSurfaceFX implements PSurface { } - public void setSize(int width, int height) { + public void setSize(int wide, int high) { + // When the surface is set to resizable via surface.setResizable(true), + // a crash may occur if the user sets the window to size zero. + // https://github.com/processing/processing/issues/5052 + if (high <= 0) { + high = 1; + } + if (wide <= 0) { + wide = 1; + } + //System.out.format("%s.setSize(%d, %d)%n", getClass().getSimpleName(), width, height); Scene scene = stage.getScene(); double decorH = stage.getWidth() - scene.getWidth(); double decorV = stage.getHeight() - scene.getHeight(); - stage.setWidth(width + decorH); - stage.setHeight(height + decorV); - fx.setSize(width, height); + stage.setWidth(wide + decorH); + stage.setHeight(high + decorV); + fx.setSize(wide, high); } diff --git a/core/src/processing/opengl/PSurfaceJOGL.java b/core/src/processing/opengl/PSurfaceJOGL.java index a65586ed8..bde0f5230 100644 --- a/core/src/processing/opengl/PSurfaceJOGL.java +++ b/core/src/processing/opengl/PSurfaceJOGL.java @@ -745,19 +745,29 @@ public class PSurfaceJOGL implements PSurface { } - public void setSize(final int width, final int height) { + public void setSize(int wide, int high) { if (pgl.presentMode()) return; - boolean changed = sketch.width != width || sketch.height != height; + // When the surface is set to resizable via surface.setResizable(true), + // a crash may occur if the user sets the window to size zero. + // https://github.com/processing/processing/issues/5052 + if (high <= 0) { + high = 1; + } + if (wide <= 0) { + wide = 1; + } - sketchWidth = width; - sketchHeight = height; + boolean changed = sketch.width != wide || sketch.height != high; - sketch.setSize(width, height); - graphics.setSize(width, height); + sketchWidth = wide; + sketchHeight = high; + + sketch.setSize(wide, high); + graphics.setSize(wide, high); if (changed) { - window.setSize(width * windowScaleFactor, height * windowScaleFactor); + window.setSize(wide * windowScaleFactor, high * windowScaleFactor); } } diff --git a/core/todo.txt b/core/todo.txt index 72676d9b4..d43eed346 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -1,6 +1,5 @@ 0263 (3.3.6 or 3.4) - gohai X shell discussion with gohai X https://github.com/processing/processing/pull/5082 @@ -15,6 +14,11 @@ X https://github.com/processing/processing/issues/5182 X https://github.com/processing/processing/issues/5183 X https://github.com/processing/processing/issues/5194 +contrib +X Add workaround for window size = 0 crash +X https://github.com/processing/processing/pull/5234 +X https://github.com/processing/processing/issues/5052 + _ when doing createFont, can we add it to the os fonts available? diff --git a/todo.txt b/todo.txt index 22d1611fd..9a8cb3645 100755 --- a/todo.txt +++ b/todo.txt @@ -2,15 +2,14 @@ X update to Java 8u144 X fix issue with call to remove value instead of key in mode contrib hash X this was only in the code used by the command line mode loader +o data folder not exporting on macOS? +o https://github.com/processing/processing/issues/5207 +X confirmed working with LoadDisplayImage example _ make setting the window icon automatic, based on files in local dirs X https://github.com/processing/processing/issues/5123 X https://github.com/processing/processing/pull/5202 _ need to make this work behind the scenes instead _ create icon.png or have an 'icons' folder with multiple sizes -_ movie maker a little broken -_ https://github.com/processing/processing/issues/5168 -_ data folder not exporting on macOS? -_ https://github.com/processing/processing/issues/5207 contrib X add Italian translation @@ -21,6 +20,11 @@ X https://github.com/processing/processing/issues/5165 X typo in German translation X https://github.com/processing/processing/pull/5195 X https://github.com/processing/processing/issues/5187 +X movie maker a little broken +X https://github.com/processing/processing/issues/5168 +X https://github.com/processing/processing/pull/5230 +X Add more build products to linux/.gitignore +X https://github.com/processing/processing/pull/5229 jakub X Fix comment/uncomment adding slashes at wrong indent