GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — `set()` method throws `NullPointerException` for `PGraphicsOpenGL` objects · Issue #1520 · processing/processing4

set() method throws NullPointerException for PGraphicsOpenGL objects #1520

New issue
Copy link
New issue
Copy link
Closed
Closed
set() method throws NullPointerException for PGraphicsOpenGL objects#1520
Copy link
Assignees
hx2A
Labels
bugSomething isn't workingSomething isn't working

Description

@hx2A
hx2A
opened on May 21, 2026
Issue body actions

Most appropriate sub-area of Processing 4?

Core/Environment/Rendering

Processing version

4.5.2

Operating system

Linux (Unbuntu) and MacOS Tahoe

Bug description

I get a null pointer exception when I pass a PGraphics object to the background() method.

For some reason the PDE doesn't display the stack trace, I just see this:

NullPointerException
NullPointerException

Steps to reproduce this

The example code below reproduces the bug.

snippet

PGraphics g;

void setup() {
  size(300, 300, P3D);
  
  g = createGraphics(width, height, P2D);
  g.beginDraw();
  g.background(0, 255, 0);
  g.endDraw();
}

void draw() {
  background(g);
}

I am able to get a stack trace when I use the equivalent code in py5. I traced the problem to the PGraphics object's null pixels array.

One possible workaround is to insert a g.loadPixels() call after g.endDraw(). That fixes the problem. Another workaround is to get() a PImage object:

PGraphics g;
PImage img;

void setup() {
  size(300, 300, P3D);
  
  g = createGraphics(width, height, P2D);
  g.beginDraw();
  g.background(0, 255, 0);
  g.endDraw();
  img = g.get();
}

void draw() {
  background(img);
}

Additional context

Either workaround suggests a solution. I'm happy to make a PR to fix this, you can assign it to me.

Would you like to work on the issue?

Yes, I’d like to help with this

Activity

  1. hx2A
    added
    bugSomething isn't workingSomething isn't working
    on May 21, 2026
  2. catilac
    assigned
    hx2A
    on Jul 13, 2026
  3. catilac commented on Jul 13, 2026

    @catilac
    catilac
    on Jul 13, 2026
    Collaborator
    More actions

    Thanks @hx2A! Assigned to you.

  4. hx2A commented on Jul 15, 2026

    @hx2A
    hx2A
    on Jul 15, 2026
    ContributorAuthor
    More actions

    Thank you @catilac ! This bug fix is pretty straightforward and I'll get it done.

    Reacted by Raphaël de Courville, Moon and Xin Xin
  5. catilac commented on Jul 15, 2026

    @catilac
    catilac
    on Jul 15, 2026
    Collaborator
    More actions

    thanks @hx2A really appreciate your help :)

  6. hx2A
    changed the title [-]`background()` method throws `NullPointerException` for `PGraphics` objects[/-] [+]`set()` method throws `NullPointerException` for `PGraphicsOpenGL` objects[/+] on Jul 31, 2026
  7. hx2A commented on Jul 31, 2026

    @hx2A
    hx2A
    on Jul 31, 2026
    ContributorAuthor
    More actions

    Renaming this because I see void backgroundImpl(PImage image) calls set(0, 0, image), and I can reproduce the bug with set(0, 0, g) also. And this bug only applies to PGraphicsOpenGL instances.

  8. hx2A commented on Jul 31, 2026

    @hx2A
    hx2A
    on Jul 31, 2026
    ContributorAuthor
    More actions

    I created a PR for this, it is running the checks.

    #1557

    Here is test code:

    PGraphics g;
    
    void setup() {
      size(300, 300, P3D);
      
      g = createGraphics(width, height, P2D);
      g.beginDraw();
      g.background(0, 255, 0);
      g.endDraw();
    }
    
    void draw() {
      // background(g);
      set(0, 0, g);
    }
  9. hx2A commented on Jul 31, 2026

    @hx2A
    hx2A
    on Jul 31, 2026
    ContributorAuthor
    More actions

    Other permutations of renderer type or graphics type don't experience the problem. The bug only appears when both the Sketch and the graphics object are PGraphicsOpenGL instances. The bug is triggered with background() or set().

  10. catilac
    closed this as completedin c83c84aon Jul 31, 2026
  11. hx2A commented on Jul 31, 2026

    @hx2A
    hx2A
    on Jul 31, 2026
    ContributorAuthor
    More actions

    Awesome, thank you for merging @catilac

    Next up, #1422

    Reacted by Xin Xin
  12. pull
    added a commit that references this issue on Jul 31, 2026

    fix processing#1520 (processing#1557)

    This issue will close once commit c83c84a is merged into the 'main' branch.
    c83c84a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @hx2A
    hx2A

Labels

bugSomething isn't workingSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.