processing / processing/processing4

NullPointerException on Dynamic Window Resize in Processing

Ouverte
#1,146 6 commentaires 0 réactions 1 personne assignée Voir sur GitHub

@tudasamenc y travaille déjà.

Depuis le 10/7/2025.

bug
Langage dominant
Java
Étoiles
494
Forks
183
Merge moyen
4 h 39 min
PR mergées (30 j)
3

Description

Most appropriate sub-area of Processing 4?

Core/Environment/Rendering

Processing version

4.4.4

Operating system

Windows 10

Steps to reproduce this

1. Description :
When dynamically resizing a Processing sketch window (via surface.setSize(w, h) or by enabling surface.setResizable(true)), a NullPointerException may occur in Component$BltBufferStrategy.revalidate(...), due to an internal backBuffers[] array being null.

This happens during the rendering phase, likely due to an invalidated or uninitialized BufferStrategy after the resize.

2. Example Stack Trace :

java.lang.NullPointerException: Cannot invoke "java.awt.image.VolatileImage.validate(java.awt.GraphicsConfiguration)" because "this.backBuffers[...]" is null
    at java.desktop/java.awt.Component$BltBufferStrategy.revalidate(Component.java:4552)
    at java.desktop/java.awt.Component$BltBufferStrategy.getDrawGraphics(Component.java:4449)
    at processing.awt.PSurfaceAWT.render(PSurfaceAWT.java:242)
    at processing.awt.PSurfaceAWT$9.callDraw(PSurfaceAWT.java:1389)
    at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:356)

3. Expected Behavior :
When resizing the window, either manually (with setResizable(true)) or programmatically (via surface.setSize(w, h)), the sketch should continue rendering smoothly without crashing or throwing an exception.

snippet

// Paste your code below :)

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

void draw() {
  background(200);
}
Additional context

Discovered Workaround :

Calling surface.setVisible(true) immediately after resizing prevents the crash :

surface.setSize(w, h);
surface.setVisible(true);               // Prevents the NPE
Would you like to work on the issue?

No

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.