[SOLVED] I get a NullPointerException when switching from the default rendering technique to JavaFX 2D

I found the error. The problem lies with my cp5 initializations, which is done in the void keyPressed() section:

void keyPressed() {
  cp5 = new ControlP5(this);
  cp5.addButton("open");
  cp5.addButton("closePort");
  cp5.addButton("refresh");
  cp5.addScrollableList("comlist").close();
  String list[] = Serial.list();
  cp5.get(ScrollableList.class, "comlist").addItems(list);
    
  MyController = new ControlP5(this);
  MyController.addSlider("K_factor",0,30,1,slider_K_X,slider_K_Y,slider_W,slider_H); 
  MyController.addSlider("tau_I",0,10,0,slider_tau_I_X,slider_tau_I_Y,slider_W,slider_H);
  MyController.addSlider("tau_D",0,10,0,slider_tau_D_X,slider_tau_D_Y,slider_W,slider_H);
  MyController.addSlider("DB",0,1,0,slider_DB_X,slider_DB_Y,slider_W,slider_H);
}

This works perfectly when using the default renderer. But, when I use the JavaFX 2D renderer, that’s when I get the NPE.

So, when I put these initialization lines of code in comment (while JavaFX 2D is on), my program works again, and does not show a NPE.

Then I thought that, maybe if I initialize these cp5 objects in the setup() section instead of the keypressed() section it will work. But, when I do this, I get a NPE again…