Skip to content

NullPointerException on Dynamic Window Resize in Processing #1146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
famousgrouse44 opened this issue Jun 14, 2025 · 1 comment
Open

NullPointerException on Dynamic Window Resize in Processing #1146

famousgrouse44 opened this issue Jun 14, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@famousgrouse44
Copy link

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

@famousgrouse44 famousgrouse44 added the bug Something isn't working label Jun 14, 2025
@SableRaf
Copy link
Collaborator

Hi @famousgrouse44 and thanks for reporting and investigating this issue. Resizeable windows are a relatively new feature in Processing and they could definitely use a little more love.

I noticed something similar but with a different error message here.

Screen.Recording.2025-04-01.at.21.31.53.mov

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants