# G4P - Placing a GView Within a GWindow

**URL:** https://discourse.processing.org/t/g4p-placing-a-gview-within-a-gwindow/27575
**Category:** Libraries
**Created:** [February 4, 2021, 2:24am UTC](https://discourse.processing.org/t/g4p-placing-a-gview-within-a-gwindow/27575 "2021-02-04T02:24:45Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![MauiMana](https://avatars.discourse-cdn.com/v4/letter/m/91b2a8/32.png) [@MauiMana](https://discourse.processing.org/u/MauiMana)
#### Post date: [February 4, 2021, 2:24am UTC](https://discourse.processing.org/t/g4p-placing-a-gview-within-a-gwindow/27575/1 "2021-02-04T02:24:46Z")

</div>

_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)**_  
_ **##############################################################** _

---

<div class="post-metadata">

### Author: ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)
#### Post date: [February 4, 2021, 10:59am UTC](https://discourse.processing.org/t/g4p-placing-a-gview-within-a-gwindow/27575/2 "2021-02-04T10:59:38Z")

</div>

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 😞

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. 🙂

---

<div class="post-metadata">

### Author: ![MauiMana](https://avatars.discourse-cdn.com/v4/letter/m/91b2a8/32.png) [@MauiMana](https://discourse.processing.org/u/MauiMana)
#### Post date: [February 5, 2021, 1:44am UTC](https://discourse.processing.org/t/g4p-placing-a-gview-within-a-gwindow/27575/3 "2021-02-05T01:44:40Z")

</div>

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.
