loop() doesn't seem to work with P2D renderer.

edited February 2017 in How To...

I am running a system with a window that is hidden and then can come back. When it is hidden, noLoop() is called, and then loop() is called when restarting. It works fine, but when I switch to using P2D instead of the default renderer, draw stops getting called after restarting. I know that loop() is getting called, but draw is not getting called.

Note: I am removing all the window listeners from the window, maybe a window listener that is specific to the OpenGL version of the window is needed to make draw get called?

Answers

  • edited February 2017

    The opengl windows have two window listeners which are getting removed, while the default ones have only one. Don't know if that has anything to do with it.

    Edit: It still doesn't work if I remove only one of them, I have tried removing each separately, but this did not fix the error.

  • edited February 2017

    Perhaps try out my removeWindowListener() solution: :-/
    https://forum.Processing.org/two/discussion/17310/intercept-window-closure-in-p2d-renderer-processing-3#Item_5

    It checks out "processing.opengl.PSurfaceJOGL" before removing each WindowListener. *-:)

  • edited February 2017

    Selectively removing any listeners isn't fixing this, I have tried each combination of listeners. For some reason, draw stops getting called when the window is closed (it wasn't getting stopped by noLoop()) even if all window listeners are removed.

    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    //import com.jogamp.newt.event.WindowAdapter;
    import com.jogamp.newt.event.WindowListener;
    import com.jogamp.newt.event.WindowUpdateEvent;
    
    void setup() {
      size(100, 100, P2D);
      if (g.isGL()) {
        fixExitGl();
      } else {
        fixExit();
      }
    }
    
    void draw() {
      println("draw"+millis());
    }
    
    void mousePressed() {
      noLoop();
    }
    
    void mouseReleased() {
      loop();
    }
    
    final void fixExitGl() {
      com.jogamp.newt.opengl.GLWindow win = ((com.jogamp.newt.opengl.GLWindow) getSurface().getNative());
      for (final WindowListener evt : win.getWindowListeners()) {
        win.removeWindowListener(evt);
      }
    }
    final void fixExit() {
      java.awt.Window win = ((processing.awt.PSurfaceAWT.SmoothCanvas) getSurface().getNative()).getFrame();
      for (final java.awt.event.WindowListener evt : win.getWindowListeners()) {
        win.removeWindowListener(evt);
      }
    }
    

    When the close button is clicked, the window closes, but the program remains running. Even so, draw does not continue getting called. This happens with P2D, but not the default renderer.

  • edited February 2017

    I have tried overriding the exit() function, but that doesn't work either. In fact, exit() isn't even getting called.

  • Answer ✓

    Finally found the problem. Line 3630 of PApplet.java, it stops the thread from running when the window is closed. I re-wrote the dispose method and was able to stop this from happening, but it does cause an error to occur when the program is finally closed.

Sign In or Register to comment.