Skip to content

FX2D not usable as offscreen buffer #13

Description

@EGjoni

In 3.2.1, when attempting to draw into an FX2D PGraphics context which is not the main context as shown in this code:

PGraphics secondBuff; 

void setup() {
  size(400, 300, FX2D); 
  secondBuff = createGraphics(400, 300, FX2D); 
}

void draw() {
 background(100); 
 this.getGraphics().endDraw();

 secondBuff.beginDraw();
 secondBuff.strokeWeight(10);
 secondBuff.stroke(255);
 secondBuff.point(mouseX, mouseY);
 secondBuff.endDraw();

 this.getGraphics().beginDraw();
 image(secondBuff, 0,0);
}

The following error is thrown:

java.lang.NullPointerException
    at processing.javafx.PGraphicsFX2D.fillFromCalc(PGraphicsFX2D.java:1951)
    at processing.core.PGraphics.fill(PGraphics.java:6669)
    at processing.core.PGraphics.defaultSettings(PGraphics.java:963)
    at processing.core.PGraphics.checkSettings(PGraphics.java:938)
    at processing.javafx.PGraphicsFX2D.beginDraw(PGraphicsFX2D.java:147)
    at sketch_160827a.draw(sketch_160827a.java:28)
    at processing.core.PApplet.handleDraw(PApplet.java:2412)
    at processing.javafx.PSurfaceFX$1.handle(PSurfaceFX.java:83)
    at processing.javafx.PSurfaceFX$1.handle(PSurfaceFX.java:1)
    at com.sun.scenario.animation.shared.TimelineClipCore.visitKeyFrame(TimelineClipCore.java:239)
    at com.sun.scenario.animation.shared.TimelineClipCore.playTo(TimelineClipCore.java:197)
    at javafx.animation.Timeline.impl_playTo(Timeline.java:176)
    at javafx.animation.AnimationAccessorImpl.playTo(AnimationAccessorImpl.java:39)
    at com.sun.scenario.animation.shared.InfiniteClipEnvelope.timePulse(InfiniteClipEnvelope.java:110)
    at javafx.animation.Animation.impl_timePulse(Animation.java:1102)
    at javafx.animation.Animation$1.lambda$timePulse$25(Animation.java:186)
    at java.security.AccessController.doPrivileged(Native Method)
    at javafx.animation.Animation$1.timePulse(Animation.java:185)
    at com.sun.scenario.animation.AbstractMasterTimer.timePulseImpl(AbstractMasterTimer.java:344)
    at com.sun.scenario.animation.AbstractMasterTimer$MainLoop.run(AbstractMasterTimer.java:267)
    at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:506)
    at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:490)
    at com.sun.javafx.tk.quantum.QuantumToolkit.lambda$runToolkit$404(QuantumToolkit.java:319)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
    at java.lang.Thread.run(Thread.java:745)
handleDraw() called before finishing
Could not run the sketch (Target VM failed to initialize).
For more information, read revisions.txt and Help ? Troubleshooting.

In contrast, if the offscreen PGraphics context is specified as JAVA2D, things work as expected:

PGraphics secondBuff; 

void setup() {
  size(400, 300, FX2D); 
  secondBuff = createGraphics(400, 300, JAVA2D); 
}

void draw() {
 background(100); 
 this.getGraphics().endDraw();

 secondBuff.beginDraw();
 secondBuff.strokeWeight(10);
 secondBuff.stroke(255);
 secondBuff.point(mouseX, mouseY);
 secondBuff.endDraw();

 this.getGraphics().beginDraw();
 image(secondBuff, 0,0);
}

Additionally (and I'm not sure if this should be filed as a separate issue), using an FX2D context as an offscreen buffer when the main context is anything other than FX2D results in a null pointer exception on the first line calling any of the FX2D context's draw functions. However, the IDE provides no stack trace when this happens.

`

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions