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

There is also a windowResize(newWidth, newHeight); does calling that in each loop of draw() help?

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

void draw() {
  windowResize(width, height);
  rect(0,0,width,height);
}