processing4 icon indicating copy to clipboard operation
processing4 copied to clipboard

Calling `windowResize()` with multiple `PApplet` instances running destabilizes the sketch

Open onimatrix opened this issue 3 years ago • 3 comments

Description

Modifying the MultipleWindows example to use P3D for the main window and JAVA2D for the child one, plus doing a windowResize in the ChildApplet::draw() method, leaves the child window frozen.

ChildApplet childA;

void setup()
{
  size(400, 300, P3D);    
  childA = new ChildApplet();
}

class ChildApplet extends PApplet
{
  ChildApplet()
  {
    super();
    PApplet.runSketch(new String[] { this.getClass().getName() }, this);
  }

  void settings()
  {
    size(400, 300);
  }

  void setup()
  {
    windowResizable(true);
  }

  void draw()
  {
    println("frame #" + frameCount);
    windowResize(width + 1, height); 
  }
}

There's a second, (maybe related?) issue, where calling windowMove and windowResize on a simple sketch's draw() triggers an exception with every frame for P2D and P3D, and freezes completely in JAVA2D

void settings()
{
  size(400, 300, P2D);
}

void setup()
{
  windowResizable(true);
}

void draw()
{
  windowMove(20, 20);
  println("frame #" + frameCount);
  windowResize(width + 1, height); 
}

It seems that calling windowMove before calling windowResize is what triggers the issue here. If I move windowMove to setup() instead, it only triggers the issue once and then resizes successfully (but remains frozen in JAVA2D)

Thank you for your time!

Your Environment

This is happening on Windows 10 with Processing 4.1.1.

Possible Causes / Solutions

Might be related to #507?

onimatrix avatar Jan 03 '23 20:01 onimatrix

When you have more than one PApplet running at a time, things are going to get messy very quickly… We'll have to see about a fix, but that'll mostly be in #507.

benfry avatar Jan 18 '23 14:01 benfry

For some reason, not really affected by the Fullscreen button for the window itself, or the windows "snap to position" feature.

Only freezes when resizing from the edges after about 1 second.


Update: Fixed by specifying P2D renderer. Update: Using P2D renderer though doesn't allow me to close the child sketch window.

This worked fine in Processing 3. We should be able to create child windows of the main process that can be resized and closed.

retiutut avatar Jun 15 '23 19:06 retiutut

Investigated this again. Window resizing is broken for JAVA2D, but not for P2D.

If we could only exit() in the child PApplet class while using P2D renderer using default implementation or something like

    @Override
    void exit() {
        dispose();
    }

The above is what I was doing in Processing 3 with JAVA2D. If you don't override exit() and you close the child PApplet, it usually closes the child and the parent.

retiutut avatar Jul 12 '23 01:07 retiutut