Program "crashes" when I setResizable(true) and resize the Window

Processing is responsible for calling the draw() method 60 times a second (default). Processing also provides methods to change the framerate, enable/disable looping and redraw the screen on demand (when not looping).

When the sketch is launched a pre-processor takes the users source code and wraps it into a class that extends the PApplet class (provided by Processing). So the user’s setup() and draw() methods override the ones in PApplet.

Java doesn’t have a native window resize event (at least it didn’t, don’t know about latest versions) letting the OS perform the actual resize, leaving the content to the app. Processing regularly checks the size of window and updates the width and height variables.

One thing you might try is to change the default JAVA2D renderer for P2D as they use different window classes

JAVA2D - JFrame
P2D - com.jogamp.newt.opengl.GLWindow

1 Like

Doing JAVA2D or P2D worked, I also increased the minimum window size and I used ur solution from 2016 lol

After 7 years I can be forgiven for forgetting my own posts LOL.

For others interested the 2016 discussion provided one answer based on code provided by GoToLoop and myself.

After a googling to find the 2016 post I found this discussion from 2018 where I show a simple safe way for your sketch to detect a change in the width or height

Hope these provide an insight into the window resize topic. :grinning:

1 Like

you could also use windowResized() as it’s called when the window is resized

2 Likes

you could also use windowResized() as it’s called when the window is resized

How did you use this? According to the documentation it doesn’t return anything:https://processing.org/reference/windowResized_.html

Think of it as when the window is resized that method is called. this allows u to be able to do anything after the window is resized with is what pre() is doing in this discussion.

1 Like

I see, something like the following. But you said it stopped working in your original demo.

int counter = 0;

void setup() {
  size(400, 400);
  surface.setResizable(true);
}

void windowResized(){
  println("window resized :", counter); 
  counter++;
}

void draw(){
  background(0);
  fill(255);
  rect(0,0,width,height);
}

everything stopped working the program crashed