size() sometimes erratic (i.e default size used), especially w/ large setup() functions #1672

Closed
deisner opened this Issue Mar 1, 2013 · 15 comments

Comments

Projects
None yet
6 participants
@deisner

deisner commented Mar 1, 2013

I'm running a "Hello, World" type sketch on Ubuntu Linux (12.04 LTS). The size() method, invoked as the first statement in my setup() method, does not appear to be working correctly. The size of the output window is set correctly, but the width and height variables remain at 100x100, and the drawing area appears to be clipped at 100x100, too (based on other testing).

When I run the same sketch on Windows it works as expected. See attached screen captures. In both cases I'm using Processing 2.0b8.

Here is the sketch:

void setup() {
  size(480, 320);
  noLoop();
}

void draw() {

  int centX = width/2;
  int centY = height/2;
  println( "width, height: " + width +", "+height);
  ellipse( centX, centY, 0.8*width, 0.8*height);
}

Linux output:
linux_screenshot

Linux PDE:
linux_pde

Windows output:
windows_screenshot

Windows PDE:
windows_pde

@deisner deisner closed this Mar 1, 2013

@deisner deisner reopened this Mar 1, 2013

@benfry

This comment has been minimized.

Show comment
Hide comment
@benfry

benfry Mar 1, 2013

Member

Are you using OpenJDK?

Member

benfry commented Mar 1, 2013

Are you using OpenJDK?

@deisner

This comment has been minimized.

Show comment
Hide comment
@deisner

deisner Mar 2, 2013

No. It's using the Java that's packed with processing:

$ ls -l /proc/$(ps -ef |grep [p]rocessing | awk '{print $2}')/exe
lrwxrwxrwx 1 david david 0 Mar  2 13:09 /proc/4401/exe -> /opt/processing/processing-2.0b8/java/bin/java
$ /opt/processing/processing-2.0b8/java/bin/java -version
java version "1.6.0_37"
Java(TM) SE Runtime Environment (build 1.6.0_37-b06)
Java HotSpot(TM) Client VM (build 20.12-b01, mixed mode, sharing)

deisner commented Mar 2, 2013

No. It's using the Java that's packed with processing:

$ ls -l /proc/$(ps -ef |grep [p]rocessing | awk '{print $2}')/exe
lrwxrwxrwx 1 david david 0 Mar  2 13:09 /proc/4401/exe -> /opt/processing/processing-2.0b8/java/bin/java
$ /opt/processing/processing-2.0b8/java/bin/java -version
java version "1.6.0_37"
Java(TM) SE Runtime Environment (build 1.6.0_37-b06)
Java HotSpot(TM) Client VM (build 20.12-b01, mixed mode, sharing)
@freakabcd

This comment has been minimized.

Show comment
Hide comment
@freakabcd

freakabcd Mar 13, 2013

I get output identical to your Windows output on my Kubuntu 12.04 LTS running git-master and processing 2.0b8 using both the included JRE and OpenJDK.

$ cd /home/freakabcd/software/processing-2.0b8
$ ./processing
$ ls -l /proc/$(pgrep -f 'processing')/exe
lrwxrwxrwx 1 freakabcd freakabcd 0 Mar 14 08:29 /proc/21737/exe -> /home/freakabcd/software/processing-2.0b8/java/bin/java
$ /home/freakabcd/software/processing-2.0b8/java/bin/java -version
java version "1.6.0_37"
Java(TM) SE Runtime Environment (build 1.6.0_37-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.12-b01, mixed mode)
$ rm -rfv java
$ ./processing
$ ls -l /proc/$(pgrep -f 'processing')/exe
lrwxrwxrwx 1 freakabcd freakabcd 0 Mar 14 08:35 /proc/22367/exe -> /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java
$ /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java -version
java version "1.6.0_27"
OpenJDK Runtime Environment (IcedTea6 1.12.3) (6b27-1.12.3-0ubuntu1~12.04.1)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)

I am wondering why your output for 'java -version' shows

HotSpot(TM) Client VM (build 20.12-b01, mixed mode, sharing)

while mine shows

HotSpot(TM) 64-bit Server VM (build 20.12-b01, mixed mode)

I downloaded processing-2.0b8-linux32.tgz and java -version from the included JRE shows

java version "1.6.0_37"
Java(TM) SE Runtime Environment (build 1.6.0_37-b06)
Java HotSpot(TM) Server VM (build 20.12-b01, mixed mode)

I do not know why the included JRE is using the Server VM on my machine as opposed to the Client VM on your machine. I'm also unsure if this makes a difference; iirc client VM simply loads faster but may not give the best performance.

I get output identical to your Windows output on my Kubuntu 12.04 LTS running git-master and processing 2.0b8 using both the included JRE and OpenJDK.

$ cd /home/freakabcd/software/processing-2.0b8
$ ./processing
$ ls -l /proc/$(pgrep -f 'processing')/exe
lrwxrwxrwx 1 freakabcd freakabcd 0 Mar 14 08:29 /proc/21737/exe -> /home/freakabcd/software/processing-2.0b8/java/bin/java
$ /home/freakabcd/software/processing-2.0b8/java/bin/java -version
java version "1.6.0_37"
Java(TM) SE Runtime Environment (build 1.6.0_37-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.12-b01, mixed mode)
$ rm -rfv java
$ ./processing
$ ls -l /proc/$(pgrep -f 'processing')/exe
lrwxrwxrwx 1 freakabcd freakabcd 0 Mar 14 08:35 /proc/22367/exe -> /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java
$ /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java -version
java version "1.6.0_27"
OpenJDK Runtime Environment (IcedTea6 1.12.3) (6b27-1.12.3-0ubuntu1~12.04.1)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)

I am wondering why your output for 'java -version' shows

HotSpot(TM) Client VM (build 20.12-b01, mixed mode, sharing)

while mine shows

HotSpot(TM) 64-bit Server VM (build 20.12-b01, mixed mode)

I downloaded processing-2.0b8-linux32.tgz and java -version from the included JRE shows

java version "1.6.0_37"
Java(TM) SE Runtime Environment (build 1.6.0_37-b06)
Java HotSpot(TM) Server VM (build 20.12-b01, mixed mode)

I do not know why the included JRE is using the Server VM on my machine as opposed to the Client VM on your machine. I'm also unsure if this makes a difference; iirc client VM simply loads faster but may not give the best performance.

@benfry

This comment has been minimized.

Show comment
Hide comment
@benfry

benfry Apr 11, 2013

Member

Looks like the window sizing event is being fired erratically on Linux. I got both versions with a few attempts. Will have to check into it...

Screen Shot 2013-04-11 at 9 38 21 AM
Screen Shot 2013-04-11 at 9 38 37 AM

Member

benfry commented Apr 11, 2013

Looks like the window sizing event is being fired erratically on Linux. I got both versions with a few attempts. Will have to check into it...

Screen Shot 2013-04-11 at 9 38 21 AM
Screen Shot 2013-04-11 at 9 38 37 AM

@benfry

This comment has been minimized.

Show comment
Hide comment
@benfry

benfry Apr 11, 2013

Member

...or even a third version that had a 100x100 window as well.

Member

benfry commented Apr 11, 2013

...or even a third version that had a 100x100 window as well.

@paul59

This comment has been minimized.

Show comment
Hide comment
@paul59

paul59 Apr 22, 2013

I have the same issue on a Slackware-based Puppy Linux - the rendering area is confined to a small rectangle in the centre of the window (although the window size is correct).

It happens most of the time but not every time.

A temporary work-around is to use 'present' instead which works properly each time.

paul59 commented Apr 22, 2013

I have the same issue on a Slackware-based Puppy Linux - the rendering area is confined to a small rectangle in the centre of the window (although the window size is correct).

It happens most of the time but not every time.

A temporary work-around is to use 'present' instead which works properly each time.

@benfry

This comment has been minimized.

Show comment
Hide comment
@benfry

benfry Apr 22, 2013

Member

Patches/code/help always welcome...

Member

benfry commented Apr 22, 2013

Patches/code/help always welcome...

@paul59

This comment has been minimized.

Show comment
Hide comment
@paul59

paul59 Apr 30, 2013

Could this somehow be down to the particular window manager being used? I've yet to experience the problem when testing via Window Maker or Fluxbox but it happens all the time when I use JWM on the same computer.

paul59 commented Apr 30, 2013

Could this somehow be down to the particular window manager being used? I've yet to experience the problem when testing via Window Maker or Fluxbox but it happens all the time when I use JWM on the same computer.

@benfry

This comment has been minimized.

Show comment
Hide comment
@benfry

benfry May 1, 2013

Member

Yes. Typically, the two things that cause the most problems on Linux are 1) window managers, and 2) people using OpenJDK.

But Ubuntu 12.04 out of the box is a "supported" platform, and I'm seeing it there, so it's certainly a problem. I assume there's just something odd happening with the event thread and the drawing thread not synching properly in PApplet.

Member

benfry commented May 1, 2013

Yes. Typically, the two things that cause the most problems on Linux are 1) window managers, and 2) people using OpenJDK.

But Ubuntu 12.04 out of the box is a "supported" platform, and I'm seeing it there, so it's certainly a problem. I assume there's just something odd happening with the event thread and the drawing thread not synching properly in PApplet.

@Sigill

This comment has been minimized.

Show comment
Hide comment
@Sigill

Sigill Jun 11, 2013

I'm actually encountering the same issue on a Debian Jessie running Gnome3 (confirmed on several computers, both 32 & 64 bits systems).

Switching the rendering mode to P2D makes size working as expected, but i get a

Smooth level 2 is not available. Using 1 instead

when running the applet, and

X11Util.Display: Shutdown (JVM shutdown: false, open (no close attempt): 1/1, reusable (open, marked uncloseable): 0, pending (open in creation order): 1)
X11Util: Open X11 Display Connections: 1
X11Util: Open[0]: NamedX11Display[:0, 0x7f998822d1c0, refCount 1, unCloseable false]
X11Util.Display: Shutdown (JVM shutdown: true, open (no close attempt): 1/1, reusable (open, marked uncloseable): 0, pending (open in creation order): 1)
X11Util: Open X11 Display Connections: 1
X11Util: Open[0]: NamedX11Display[:0, 0x7f998822d1c0, refCount 1, unCloseable false]

when closing it.

Switching to my system jre (OpenJDK 6b27-1.12.5-2 or 7u21-2.3.9-5) makes the IDE complaining about not being fond of it, but everything works out of the box.

Sigill commented Jun 11, 2013

I'm actually encountering the same issue on a Debian Jessie running Gnome3 (confirmed on several computers, both 32 & 64 bits systems).

Switching the rendering mode to P2D makes size working as expected, but i get a

Smooth level 2 is not available. Using 1 instead

when running the applet, and

X11Util.Display: Shutdown (JVM shutdown: false, open (no close attempt): 1/1, reusable (open, marked uncloseable): 0, pending (open in creation order): 1)
X11Util: Open X11 Display Connections: 1
X11Util: Open[0]: NamedX11Display[:0, 0x7f998822d1c0, refCount 1, unCloseable false]
X11Util.Display: Shutdown (JVM shutdown: true, open (no close attempt): 1/1, reusable (open, marked uncloseable): 0, pending (open in creation order): 1)
X11Util: Open X11 Display Connections: 1
X11Util: Open[0]: NamedX11Display[:0, 0x7f998822d1c0, refCount 1, unCloseable false]

when closing it.

Switching to my system jre (OpenJDK 6b27-1.12.5-2 or 7u21-2.3.9-5) makes the IDE complaining about not being fond of it, but everything works out of the box.

@benfry

This comment has been minimized.

Show comment
Hide comment
@benfry

benfry Sep 26, 2013

Member

May be related to #2039, or that might at least provide a way to test.

Member

benfry commented Sep 26, 2013

May be related to #2039, or that might at least provide a way to test.

@anorm

This comment has been minimized.

Show comment
Hide comment
@anorm

anorm Dec 12, 2013

Seeing the same thing running processing 2.1 on Ubuntu Server 12.04 without a window manager. Only running X. I didn't see the issue running processing 2.0.1 on the same machine.

Here's the sketch I'm running (in present mode):

float angle = 0;
float x = 0;
float barSpeed = 10;
int barWidth = 50;
long lastDraw = 0;
String lastText = "";
String frameRateString = "";
float frameRateTot = 0;
PGraphics gfxBackground = null;
PGraphics gfxFullCircle = null;
PGraphics gfxHalfCircle = null;
PGraphics gfxFrameRate = null;
PFont     font = null;

void setup()
{
  size(displayWidth, displayHeight, P2D);
  delay(300); // Trying workaround for #2039 => doesn't work

  noCursor();
  frameRate(-1);
  ((PJOGL)PGraphicsOpenGL.pgl).gl.setSwapInterval(1);

  background(64);

  render();
}

void render()
{
  noStroke();

  g.beginDraw();
  font = createFont("FFScala", 25);
  textFont(font);
  fill(255);
  textAlign(CENTER);
  text("Rendering...", width/2, height/2);
  textAlign(LEFT);
  //g.endDraw();

  gfxFrameRate = createGraphics(200, 40, JAVA2D);
  gfxFrameRate.beginDraw();
  gfxFrameRate.background(0);
  gfxFrameRate.endDraw();

  gfxBackground = createGraphics(width, height, JAVA2D);
  gfxBackground.beginDraw();
  gfxBackground.background(0);
  gfxBackground.noFill();
  gfxBackground.stroke(255, 255, 255);
  gfxBackground.strokeWeight(1);
  gfxBackground.rect(0, 0, width-1, height-1);
  gfxBackground.endDraw();

  gfxFullCircle = createGraphics(3*height/4, 3*height/4, JAVA2D);
  gfxFullCircle.beginDraw();
  gfxFullCircle.smooth();
  gfxFullCircle.background(0, 0, 0, 0);
  gfxFullCircle.fill(64);
  gfxFullCircle.strokeWeight(10);
  gfxFullCircle.stroke(255);
  gfxFullCircle.arc(gfxFullCircle.width/2, gfxFullCircle.height/2, 3*height/4-12, 3*height/4-12, 0, TWO_PI);
  gfxFullCircle.endDraw();

  gfxHalfCircle = createGraphics(3*height/4-48, 3*height/4-48, JAVA2D);
  gfxHalfCircle.beginDraw();
  gfxHalfCircle.smooth();
  gfxHalfCircle.background(0, 0, 0, 0);
  gfxHalfCircle.fill(255, 255, 255, 50);
  gfxHalfCircle.noStroke();
  for(float a = 0; a < PI/10; a += PI/100)
  {
    gfxHalfCircle.arc(gfxHalfCircle.width/2, gfxHalfCircle.height/2, gfxHalfCircle.width, gfxHalfCircle.height, a, PI+a-(PI/25));
  }
  gfxHalfCircle.endDraw();
} 

void draw()
{
  image(gfxBackground, 0, 0);

  // Frame rate
  frameRateTot += frameRate;
  if(frameCount % 100 == 0)
  {
    frameRateString = String.format("%1.1f Hz", frameRateTot / 100);
    frameRateTot = 0;
    gfxFrameRate = createGraphics(200, 40, P2D);
    gfxFrameRate.beginDraw();
    gfxFrameRate.background(0);
    gfxFrameRate.fill(200, 180, 180);
    gfxFrameRate.textFont(font);
    gfxFrameRate.text(frameRateString, 10, 30);
    gfxFrameRate.endDraw();
  }
  image(gfxFrameRate, 1, 1);

  // Sliding bar
  fill(255);
  rect(x, 0, barWidth, height);
  x += barSpeed;
  if(x > width + 20) x = -20;
  if(x < -20) x = width + 20;

  // Full circle
  translate(width/2, height/2);
  image(gfxFullCircle, -gfxFullCircle.width/2, -gfxFullCircle.height/2);

  // Rotating arc
  angle += TWO_PI/(frameRate);
  rotate(angle);
  image(gfxHalfCircle, -gfxHalfCircle.width/2, -gfxHalfCircle.height/2);
}

anorm commented Dec 12, 2013

Seeing the same thing running processing 2.1 on Ubuntu Server 12.04 without a window manager. Only running X. I didn't see the issue running processing 2.0.1 on the same machine.

Here's the sketch I'm running (in present mode):

float angle = 0;
float x = 0;
float barSpeed = 10;
int barWidth = 50;
long lastDraw = 0;
String lastText = "";
String frameRateString = "";
float frameRateTot = 0;
PGraphics gfxBackground = null;
PGraphics gfxFullCircle = null;
PGraphics gfxHalfCircle = null;
PGraphics gfxFrameRate = null;
PFont     font = null;

void setup()
{
  size(displayWidth, displayHeight, P2D);
  delay(300); // Trying workaround for #2039 => doesn't work

  noCursor();
  frameRate(-1);
  ((PJOGL)PGraphicsOpenGL.pgl).gl.setSwapInterval(1);

  background(64);

  render();
}

void render()
{
  noStroke();

  g.beginDraw();
  font = createFont("FFScala", 25);
  textFont(font);
  fill(255);
  textAlign(CENTER);
  text("Rendering...", width/2, height/2);
  textAlign(LEFT);
  //g.endDraw();

  gfxFrameRate = createGraphics(200, 40, JAVA2D);
  gfxFrameRate.beginDraw();
  gfxFrameRate.background(0);
  gfxFrameRate.endDraw();

  gfxBackground = createGraphics(width, height, JAVA2D);
  gfxBackground.beginDraw();
  gfxBackground.background(0);
  gfxBackground.noFill();
  gfxBackground.stroke(255, 255, 255);
  gfxBackground.strokeWeight(1);
  gfxBackground.rect(0, 0, width-1, height-1);
  gfxBackground.endDraw();

  gfxFullCircle = createGraphics(3*height/4, 3*height/4, JAVA2D);
  gfxFullCircle.beginDraw();
  gfxFullCircle.smooth();
  gfxFullCircle.background(0, 0, 0, 0);
  gfxFullCircle.fill(64);
  gfxFullCircle.strokeWeight(10);
  gfxFullCircle.stroke(255);
  gfxFullCircle.arc(gfxFullCircle.width/2, gfxFullCircle.height/2, 3*height/4-12, 3*height/4-12, 0, TWO_PI);
  gfxFullCircle.endDraw();

  gfxHalfCircle = createGraphics(3*height/4-48, 3*height/4-48, JAVA2D);
  gfxHalfCircle.beginDraw();
  gfxHalfCircle.smooth();
  gfxHalfCircle.background(0, 0, 0, 0);
  gfxHalfCircle.fill(255, 255, 255, 50);
  gfxHalfCircle.noStroke();
  for(float a = 0; a < PI/10; a += PI/100)
  {
    gfxHalfCircle.arc(gfxHalfCircle.width/2, gfxHalfCircle.height/2, gfxHalfCircle.width, gfxHalfCircle.height, a, PI+a-(PI/25));
  }
  gfxHalfCircle.endDraw();
} 

void draw()
{
  image(gfxBackground, 0, 0);

  // Frame rate
  frameRateTot += frameRate;
  if(frameCount % 100 == 0)
  {
    frameRateString = String.format("%1.1f Hz", frameRateTot / 100);
    frameRateTot = 0;
    gfxFrameRate = createGraphics(200, 40, P2D);
    gfxFrameRate.beginDraw();
    gfxFrameRate.background(0);
    gfxFrameRate.fill(200, 180, 180);
    gfxFrameRate.textFont(font);
    gfxFrameRate.text(frameRateString, 10, 30);
    gfxFrameRate.endDraw();
  }
  image(gfxFrameRate, 1, 1);

  // Sliding bar
  fill(255);
  rect(x, 0, barWidth, height);
  x += barSpeed;
  if(x > width + 20) x = -20;
  if(x < -20) x = width + 20;

  // Full circle
  translate(width/2, height/2);
  image(gfxFullCircle, -gfxFullCircle.width/2, -gfxFullCircle.height/2);

  // Rotating arc
  angle += TWO_PI/(frameRate);
  rotate(angle);
  image(gfxHalfCircle, -gfxHalfCircle.width/2, -gfxHalfCircle.height/2);
}

@benfry benfry changed the title from size() erratic on Linux (Ubuntu) to size() sometimes erratic (i.e default size used), especially w/ large setup() functions May 10, 2014

@benfry

This comment has been minimized.

Show comment
Hide comment
@benfry

benfry May 10, 2014

Member

Additional debugging can be seen at #2294 though I've closed that as a duplicate.

Member

benfry commented May 10, 2014

Additional debugging can be seen at #2294 though I've closed that as a duplicate.

@benfry

This comment has been minimized.

Show comment
Hide comment
@benfry

benfry May 10, 2014

Member

Simplest means to reproduce (thanks to @processo in #2039)

int[] array;

void setup() {
  size(600, 600);
  // temporary fix:
  // delay(100);
  array = new int[1000000];
}

void draw() {
}
Member

benfry commented May 10, 2014

Simplest means to reproduce (thanks to @processo in #2039)

int[] array;

void setup() {
  size(600, 600);
  // temporary fix:
  // delay(100);
  array = new int[1000000];
}

void draw() {
}
@benfry

This comment has been minimized.

Show comment
Hide comment
@benfry

benfry May 17, 2015

Member

This should be completely fixed in 3.0a8.

Member

benfry commented May 17, 2015

This should be completely fixed in 3.0a8.

@benfry benfry closed this May 17, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment