Why does this crash when I try to use a G4P file selector?

The following crashes as soon as G4P.selectInput is called. If I change the renderer to JAVA2D, it works.

Is G4P incompatible with P2D?

import g4p_controls.*;

PImage img;
boolean fileselected = false;


void setup(){
     size(displayWidth,displayHeight,P2D);
     frame.setResizable(true);
     frame.setSize(600, 400);
     String fname;
     fname = G4P.selectInput("Input Dialog", "png,gif,jpg,jpeg", "Image files");
     if(fname != null)
          img = loadImage(fname);

}
void draw(){
     if(fileselected);
          image(img,0,0);
}
Tagged:

Answers

  • What version of Processing are you using and what is your operating system?

  • edited August 2015

    Processing 2.2.1 OS is Windows 7 64 bit

    And its not just G4P

    selectInput("Select a file to process:", "fileSelected");

    crashes it as well. I can hard code a file to be loaded with no problem. But anything that calls up the file selector throws a java.lang null pointer exception

  • Answer ✓

    The code below worked for me. In 2.2.1 the size() method causes the setup method to be called twice, first time it simply executes size() then calls setup again. If you run the code below you get the output.

    0
    1

    It suggests that the select dialogs shouldn't be in setup ... maybe :)

    import g4p_controls.*;
    
    PImage img = null;
    boolean fileselected = false;
    int n = 0;
    
    void setup() {
      println("> " + n++);
      size(displayWidth, displayHeight, P2D);
      frame.setResizable(true);
      frame.setSize(600, 400);
      // PApplet.useNativeSelect = false; // you might try this as well
    }
    
    void keyTyped() {
      if (key == 'i' && img == null) {
        String fname;
        fname = G4P.selectInput("Input Dialog", "png,gif,jpg,jpeg", "Image files");
        img = loadImage(fname);
      }
    }
    
    void draw() {
      if (img != null)
        image(img, 0, 0);
    }
    
  • ...the size() method causes the setup method to be called twice, ...

    Take notice though that JAVA2D default renderer is unaffected by that glitch! \m/

  • That works. Thanks. I want to play around glsl filters and I get tired of looking at the same image :)

Sign In or Register to comment.