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

**URL:** <https://discourse.processing.org/t/program-crashes-when-i-setresizable-true-and-resize-the-window/42208>\
**Category:** Processing\
**Created:** [June 13, 2023, 2:28pm UTC](https://discourse.processing.org/t/program-crashes-when-i-setresizable-true-and-resize-the-window/42208 "2023-06-13T14:28:11Z")\
**Posts on this page:** 8\
**Page:** 2

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [June 14, 2023, 9:40am UTC](https://discourse.processing.org/t/program-crashes-when-i-setresizable-true-and-resize-the-window/42208/21 "2023-06-14T09:40:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Joseph](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@Joseph](https://discourse.processing.org/u/Joseph)\
**Post date:** [June 14, 2023, 3:29pm UTC](https://discourse.processing.org/t/program-crashes-when-i-setresizable-true-and-resize-the-window/42208/22 "2023-06-14T15:29:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [June 14, 2023, 3:45pm UTC](https://discourse.processing.org/t/program-crashes-when-i-setresizable-true-and-resize-the-window/42208/23 "2023-06-14T15:45:09Z")

</div>

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

For others interested the [2016 discussion](https://forum.processing.org/two/discussion/15398/limiting-window-resize-to-a-certain-minimum.html) provided one answer based on code provided by GoToLoop and myself.

After a googling to find the 2016 post I found this [discussion](https://forum.processing.org/two/discussion/comment/122682/#Comment_122682) 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. 😀

---

<div class="post-metadata">

**Author:** ![Joseph](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@Joseph](https://discourse.processing.org/u/Joseph)\
**Post date:** [June 14, 2023, 3:58pm UTC](https://discourse.processing.org/t/program-crashes-when-i-setresizable-true-and-resize-the-window/42208/24 "2023-06-14T15:58:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [June 14, 2023, 4:19pm UTC](https://discourse.processing.org/t/program-crashes-when-i-setresizable-true-and-resize-the-window/42208/25 "2023-06-14T16:19:51Z")

</div>

`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](https://processing.org/reference/windowResized_.html)

---

<div class="post-metadata">

**Author:** ![Joseph](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@Joseph](https://discourse.processing.org/u/Joseph)\
**Post date:** [June 14, 2023, 4:33pm UTC](https://discourse.processing.org/t/program-crashes-when-i-setresizable-true-and-resize-the-window/42208/26 "2023-06-14T16:33:36Z")

</div>

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](https://forum.processing.org/two/discussion/comment/122682/#Comment_122682).

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [June 14, 2023, 4:45pm UTC](https://discourse.processing.org/t/program-crashes-when-i-setresizable-true-and-resize-the-window/42208/27 "2023-06-14T16:45:09Z")

</div>

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

```auto
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);
}

```

---

<div class="post-metadata">

**Author:** ![Joseph](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@Joseph](https://discourse.processing.org/u/Joseph)\
**Post date:** [June 14, 2023, 4:56pm UTC](https://discourse.processing.org/t/program-crashes-when-i-setresizable-true-and-resize-the-window/42208/28 "2023-06-14T16:56:43Z")

</div>

everything stopped working the program crashed

[Previous page](https://discourse.processing.org/t/program-crashes-when-i-setresizable-true-and-resize-the-window/42208.md?page=1)
