Skip to content

Commit fda1a0b

Browse files
committed
fixed bug
1 parent ecd219b commit fda1a0b

3 files changed

Lines changed: 61 additions & 6 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import processing.core.PApplet;
2+
import processing.awt.PSurfaceAWT;
3+
4+
// Reproduction of issue #1003
5+
// Resizeable causes crash on linux mint
6+
public class Issue1003 extends PApplet {
7+
8+
public void settings(){
9+
size(200, 200);
10+
}
11+
12+
public void setup() {
13+
((PSurfaceAWT) surface).setTitle("Hello world!");
14+
((PSurfaceAWT) surface).setResizable(true);
15+
// surface.setLocation(100, 100);
16+
}
17+
18+
public void draw(){
19+
// ((PSurfaceAWT) surface).setResizable(true);
20+
21+
background(frameCount % 255);
22+
line(0, 0, width, height);
23+
line(width, 0, 0, height);
24+
}
25+
public static void main(String[] passedArgs) {
26+
String[] appletArgs = new String[]{ Issue1003.class.getName()};
27+
if (passedArgs != null) {
28+
PApplet.main(concat(appletArgs, passedArgs));
29+
} else {
30+
PApplet.main(appletArgs);
31+
}
32+
33+
}
34+
}

core/src/processing/awt/PSurfaceAWT.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,15 @@ public class PSurfaceAWT extends PSurfaceNone {
4949
GraphicsDevice displayDevice;
5050

5151
// used for canvas to determine whether resizable or not
52-
// boolean resizable; // default is false
52+
boolean resizable; // default is false
5353

5454
// Internally, we know it's always a JFrame (not just a Frame)
5555
// JFrame frame;
5656
// Trying Frame again with a11 to see if this avoids some Swing nastiness.
5757
// In the past, AWT Frames caused some problems on Windows and Linux,
5858
// but those may not be a problem for our reworked PSurfaceAWT class.
5959
JFrame frame;
60+
boolean frameSetupComplete;
6061

6162
// Note that x and y may not be zero, depending on the display configuration
6263
Rectangle screenRect;
@@ -85,6 +86,8 @@ public PSurfaceAWT(PGraphics graphics) {
8586
//this.graphics = graphics;
8687
super(graphics);
8788

89+
this.resizable = false; // Default is false, can be changed with surface.setResizable()
90+
8891
/*
8992
if (checkRetina()) {
9093
// System.out.println("retina in use");
@@ -196,8 +199,7 @@ public Dimension getMinimumSize() {
196199

197200
@Override
198201
public Dimension getMaximumSize() {
199-
//return resizable ? super.getMaximumSize() : getPreferredSize();
200-
return frame.isResizable() ? super.getMaximumSize() : getPreferredSize();
202+
return resizable ? super.getMaximumSize() : getPreferredSize();
201203
}
202204

203205

@@ -442,7 +444,12 @@ public void initFrame(final PApplet sketch) {/*, int backgroundColor,
442444

443445
// disabling resize has to happen after pack() to avoid apparent Apple bug
444446
// https://github.com/processing/processing/issues/506
445-
frame.setResizable(false);
447+
// Must use this.resizable to avoid bug where value is set before initFrame is finished
448+
// https://github.com/processing/processing4/issues/1003
449+
System.out.println("Resizable in initFrame: " + this.resizable);
450+
// setResizable(this.resizable);
451+
// frame.setResizable(true);
452+
// frame.setResizable(this.resizable);
446453

447454
frame.addWindowListener(new WindowAdapter() {
448455
@Override
@@ -484,11 +491,18 @@ public void setTitle(String title) {
484491
/** Set true if we want to resize things (default is not resizable) */
485492
@Override
486493
public void setResizable(boolean resizable) {
487-
//this.resizable = resizable; // really only used for canvas
494+
this.resizable = resizable; // we need to store this so if frame init is not complete then we know the value
488495

496+
System.out.println("Frame in setResizable:" + frame);
489497
if (frame != null) {
490-
frame.setResizable(resizable);
498+
frame.setResizable(this.resizable);
499+
System.out.println("PSurfaceAWT.frame.resizable set to:" + frame.isResizable());
500+
// frame.isValid();
501+
frame.validate();
502+
System.out.println("PSurfaceAWT.frame.isValid():" + frame.isValid());
491503
}
504+
505+
System.out.println("PSurfaceAWT.resizable set to:" + this.resizable);
492506
}
493507

494508

core/src/processing/core/PApplet.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10145,8 +10145,15 @@ static public void runSketch(final String[] args,
1014510145
}
1014610146
*/
1014710147

10148+
10149+
1014810150
sketch.showSurface();
10151+
10152+
surface.setResizable(false);
10153+
10154+
1014910155
sketch.startSurface();
10156+
1015010157
}
1015110158

1015210159

0 commit comments

Comments
 (0)