G4P - Placing a GView Within a GWindow

Using the latest version of Processing 3 as well as the latest version of G4P, I’m trying to have a rotating box animating within a popup form. To do this I am using a GWindow (for the ‘popup from’) that has a GView within it *(where the rotating box is drawn and animated). And FWIW the GWindow also has a GLabel and a GButton in it as well. As far as ‘ownership’ goes, the GView (uses a P3D render) is owned by the GWindow (uses a P2D render) which in turn is owned by the original PApplet sketch (uses a P2D render). This ‘ownership’ hierarchy appears to cause an OpenGL error at the point where the GView is instantiated (see below). However if I use the original PApplet sketch as the GView’s owner than the animated box renders fine, but of course in the original PApplet window and not the GWindow I need it to. Also, as you can see from the stack trace below, the creation of both the GWindow and GView are initiated within an event handler assigned to a GDropList (owned by the original PApplet sketch). (user selects the box to be animated from a drop list)…

In any case, having the GView owned by the GWindow as desired leads to the following OpenGL message and accompanying exception to occur (and I believe it is at the point where the the GView is instantiated):

You are trying to draw outside OpenGL’s animation thread.
Place all drawing commands in the draw() function, or inside
your own functions as long as they are called from draw(),
but not in event handling functions such as keyPressed()
or mousePressed().

################ EXCEPTION IN EVENT HANDLER ################
An error occured during execution of the eventhandler:
CLASS: BoxManager METHOD: handleBoxSelectionForRendering
Caused by java.lang.NullPointerException
processing.opengl.PJOGL.clearColor(PJOGL.java:1843)
processing.opengl.PGL.clearBackground(PGL.java:665)
processing.opengl.PGraphicsOpenGL.backgroundImpl(PGraphicsOpenGL.java:5295)
processing.core.PGraphics.backgroundFromCalc(PGraphics.java:7450)
processing.core.PGraphics.background(PGraphics.java:7385)
g4p_controls.GView.(Unknown Source)
BoxRenderingGUI.setupRendering(BoxRenderingGUI.java:128)
BoxRenderingGUI.createForm(BoxRenderingGUI.java:85)
BoxRenderingGUI.(BoxRenderingGUI.java:54)
BoxManager.handleBoxSelectionForRendering(BoxManager.java:173)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
g4p_controls.GAbstractControl.fireEvent(Unknown Source)
g4p_controls.GDropList.mouseEvent(Unknown Source)
g4p_controls.GWindowImpl.mouseEvent(Unknown Source)
sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
processing.core.PApplet$RegisteredMethods.handle(PApplet.java:1436)
processing.core.PApplet.handleMethods(PApplet.java:1638)
processing.core.PApplet.handleMouseEvent(PApplet.java:2749)
processing.core.PApplet.dequeueEvents(PApplet.java:2652)
processing.core.PApplet.handleDraw(PApplet.java:2493)
processing.opengl.PSurfaceJOGL$DrawListener.display(PSurfaceJOGL.java:866)
jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:692)
jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:674)
jogamp.opengl.GLAutoDrawableBase$2.run(GLAutoDrawableBase.java:443)
jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1293)
jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:1147)
com.jogamp.newt.opengl.GLWindow.display(GLWindow.java:759)
com.jogamp.opengl.util.AWTAnimatorImpl.display(AWTAnimatorImpl.java:81)
com.jogamp.opengl.util.AnimatorBase.display(AnimatorBase.java:452)
com.jogamp.opengl.util.FPSAnimator$MainTask.run(FPSAnimator.java:178)
java.util.TimerThread.mainLoop(Timer.java:555)
java.util.TimerThread.run(Timer.java:505)
##############################################################

The GView control was included in G4P as an alternative to the GWindow, it was never my intention that it should be added to a secondary GWindow. This might explain why it doesn’t work for you :disappointed:

If you can create a really simple and short sketch that demonstrates this exception, then post it here I will play about with it and see if I can find a simple fix so G4P does what you want. :slightly_smiling_face:

I ended up simply rendering directly to the GWindow itself (it’s PGraphics obj), instead of using a nested GView. The rendering / animation is performed within a draw handler added to the GWindow. In any case, while I like the event isolation offered by the GView in the end my particular use case didn’t really need it.

I also just wanted to again thank Peter for contributing G4P to the Processing community, it has been wonderful to use and very useful.