FX2D Resizable Window Error

Switching the rendering engine to FX2D has introduced a lot of absurdities that I’ve never had to deal with before, including this issue right here:


Which was an easy, yet unexpected, fix.
However, another issue has come up. It seems as though setting the render engine to FX2D makes the window resizable by default. In my sketch, I would like the window to not be resizable. So I add this bit of code to setup():

void setup() {
  size(400, 464, FX2D);
  surface.setResizable(false);

Now, after adding that and running it, the sketch immediately closes with the most ambiguous error message that I have ever seen:

handleDraw() called before finishing
Could not run the sketch (Target VM failed to initialize).
For more information, read revisions.txt and Help ? Troubleshooting.

Now, if I keep all my code as it is, but change the rendering engine back to the default, this problem does not occur. I did some minimal research before posting this, but I couldn’t find this same issue in anyone else’s post. So please send help :smiley:

2 Likes

Put such code in initSurface() instead.

@Override
protected PSurface initSurface() {
    surface = super.initSurface();
    canvas = (Canvas) surface.getNative();
    scene = canvas.getScene();
    stage.setResizable(false);
    return surface;
}
2 Likes

Where in the code should I put this? Should I put it before or after setup()? Because I tried to put it before setup and I got errors for the variables canvas, scene, and stage saying that those variables do not exist.

Oh yeah, either define them variables in the function or outside it:

PSurfaceFX surface;
Canvas canvas;
Scene scene;
Stage stage;

You’ll have to include the relevant imports too.

1 Like

Pardon my naiveté, but what imports would those be?

import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.stage.Stage;
2 Likes

Pardon me if I’m mistaken, but it seems as though there should be another library to import because I’m still getting the message “The class PSurfaceFX does not exist”

import processing.javafx.PSurfaceFX;

2 Likes

Everytime we solve a problem, another one comes up XD. Now, this line of code is underlined in red:

surface = super.initSurface();

And the error message,
Type mismatch, “processing.core.PSurface” does not match with "processing.javafx.PSurfaceFX"

We defined the type of the surface variable as PSurfaceFX.

PSurfaceFX is a sub-type of PSurface.

super.initSurface() does indeed return a PSurfaceFX object but the compiler only knows that it is an object of type PSurface.

So, we need to cast the PSurface object that it returns to a PSurfaceFX type, so the type corresponds with the surface variable:

surface = (PSurfaceFX) super.initSurface();

2 Likes

Alright that worked, but now I get a null pointer exception on stage.setResizable(false); because the stage has not been initialized yet. I’ve been putting this code right above setup().

PSurfaceFX surface;
Canvas canvas;
Scene scene;
Stage stage;

@Override
protected PSurface initSurface() {
    surface = (PSurfaceFX) super.initSurface();
    canvas = (Canvas) surface.getNative();
    scene = canvas.getScene();
    stage.setResizable(false);
    return surface;
}

void setup() {
  size(400, 464, FX2D);
1 Like

haha. my code example was missing it:

stage = (Stage) scene.getWindow();

2 Likes

Omg it worked! Wow that was a real journey we went on for such a tiny thing XD! Thank you so much for your help.
Now, I have no idea which one of your messages I should mark as the solution because the solution is spread out over all of your messages xP