Loading...
Logo
Processing Forum

I have a problem creating a controlWindow resp. controlFrame. I'm using controlP5 with Java (Eclipse) and have a main PAplett class where you can do stuff. At the time of creating the main window, a controlWindow is opened where I put all my controls to change the behaviour in my main window. I used controlWindow and everything works but from time to time (maybe every 1 of 10 programmstarts) I get an ConcurrentModificationError while initializing the controlWindow. But I can't explain where it comes from. Both windows open, my main window looks good, my controlWindow is either complete empty or half of the buttons are there (when it's like this, it "ends" every time at the same button!). In the other 9 of 10 starts everything really works properly.

Now I read, that controlWindow shouldn't be used anymore with ControlP5 2.0+. So I wanted to use ControlFrame but don't get the example (http://www.sojamo.de/libraries/controlP5/examples/extra/ControlP5frame/ControlP5frame.pde) working. I created a 2nd class (the ControlFrame) which extends PAplett too like my main window. In my main window I can create an instance of ControlP5 (cp5=new ControlP5(this)). At the exact same line of code in my 2nd window/class I get an NullPointerException.

As I understand controlP5 correctly I have two classes which are both extending from PAplett, both of them creating a new instance of controlP5, where I add all my buttons and stuff from each window respectively. It is possible to run the 2nd window alone (which I don't need) and everything looks/starts fine (it can't work because i need my main window). When I'm starting my program with my main window I do get this NullPointer. Why is that?


The next problem I'm not sure if that has to do with the problem above is, if i use the very new controlP5 library from october I even can't write c5 = new ControlP5(this) in my main window. I instantly get an exception and no window opens.

Replies(1)

hi, I assume you are using a processing 2.0b3 or higher version and the latest controlp5 (currently 2.0.3)? the example you are linking to works for me as is on osX, processing 2.0b3 and 2.0b5. What configuration are you running?

running the ControlFrame example in OPENGL/P3D mode in 2.0b5 did not run properly therefore I have made changes to the example and have included the sketch below, which I successfully tested on osX with processing 2.0b3 and 2.0b5

regarding the problem you are encountering in your last paragraph, can you confirm that you are using a processing 2.0b3 or higher version? It seems you are running a 1.5.1 or earlier version, if this is the case, do use controlp5 1.5.2 and the ControlWindow example that comes with the library example should just work fine. 


Copy code
  1. // extra control window example when using processing 2.0b3 or higher

  2. import java.awt.Frame;

  3. import controlP5.*;

  4. private ControlP5 cp5;

  5. int def;

  6. void setup() {
  7.   size(400, 400,OPENGL);
  8.   
  9.   // here we register the method pre which will be 
  10.   // called right after setup is finished. this is required
  11.   // especially when Working in OPENGL/P3D mode where setup needs
  12.   // to finish first before dealing with controlp5 in an extra window.  
  13.   registerMethod("pre", this);
  14.   
  15. }

  16. void pre() {
  17.   // we only need to call pre() once, so lets remove it here 
  18.   unregisterMethod("pre", this);
  19.   // create a new ControlFrame, all works fine with
  20.   // processing 2.0b3 and 2.0b5 on osx
  21.   new ControlFrame(this, "extra", 200, 300);
  22. }

  23. void draw() {
  24.   background(def);
  25. }

  26. // the ControlFrame class extends PApplet, so we 
  27. // are creating a new processing applet inside a
  28. // new frame with a controlP5 object loaded
  29. public class ControlFrame extends PApplet {

  30.   int w, h;

  31.   int abc = 100;

  32.   public void setup() {
  33.     size(w, h);
  34.     frameRate(25);
  35.     cp5 = new ControlP5(this);
  36.     cp5.addSlider("abc").setRange(0, 255).setPosition(10, 10);
  37.     cp5.addSlider("def").plugTo(parent, "def").setRange(0, 255).setPosition(10, 30);
  38.     for(int i=0;i<10;i++) {
  39.       cp5.addButton("b"+i).setValue(i).setPosition(10, 50 + i*20);
  40.     }
  41.   }

  42.   public void draw() {
  43.     background(abc);
  44.   }

  45.   public void controlEvent(ControlEvent ce) {
  46.     println(ce);
  47.   }

  48.   private ControlFrame() {
  49.   }

  50.   public ControlFrame(Object theParent, String theName, int theWidth, int theHeight) {
  51.     parent = theParent;
  52.     w = theWidth;
  53.     h = theHeight;
  54.     Frame f = new Frame(theName);
  55.     f.add(this);
  56.     this.init();
  57.     f.setTitle(theName);
  58.     f.setSize(w, h);
  59.     f.setLocation(100, 100);
  60.     f.setResizable(false);
  61.     f.setVisible(true);
  62.   }

  63.   ControlP5 cp5;

  64.   Object parent;
  65. }