We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › Argh. OpenGL can only be used in a single applet!
Page Index Toggle Pages: 1
Argh. OpenGL can only be used in a single applet! (Read 2593 times)
Argh. OpenGL can only be used in a single applet!
Apr 3rd, 2008, 6:29pm
 
Hey OpenGL board.

It seems that when you open an OpenGL applet in a browser, and then close it, go about your business, but then open a different OpenGL applet — the whole thing will crap out on you with a:

javax.media.opengl.GLException: Attempt to make the same context current twice on thread.
at com.sun.opengl.impl.GLContextLock.lock(GLContextLock.java:83)


My attempts to manually work around this exception have stalled. Even if you release and then destroy your context, it still gives this same error.

Has anyone run into this before? It's quite reproducible. Try navigating here:
http://dm.risd.edu/~cvalla/pdal/assignment1.1/
Then close that, and go here:
http://dm.risd.edu/~akhoo/pdal

The second one won't load. Even more dangerous, if you navigate to it again, it will freeze your browser (tested on Safari and Firefox).

What's the deal? Are OpenGL Processing applets just inherently unsafe? Are you just supposed to navigate to one per brower-session?
Re: Argh. OpenGL can only be used in a single appl
Reply #1 - Apr 4th, 2008, 1:41am
 
Upon further investigation, it looks like this is a mac-specific problem with Processing and the JOGLAppletLauncher. Can anyone else with a mac confirm?

Here's the complete stack trace:

Thu Apr 03 19:03:40 EDT 2008 JEP creating applet com.sun.opengl.util.JOGLAppletLauncher (http://dm.risd.edu/~akhoo/HI/)
Error while running applet.
java.lang.RuntimeException: java.lang.ClassCastException: com.sun.opengl.impl.macosx.JAWT_MacOSXDrawingSurfaceInfo32

at processing.opengl.PGraphicsOpenGL.requestDisplay(PGraphicsOpenGL.java:172)

at processing.core.PApplet.run(PApplet.java:1562)

at java.lang.Thread.run(Thread.java:613)
Caused by: java.lang.ClassCastException: com.sun.opengl.impl.macosx.JAWT_MacOSXDrawingSurfaceInfo32

at com.sun.opengl.impl.macosx.MacOSXOnscreenGLDrawable.lockSurface(MacOSXOnscreenGL
Drawable.java:177)

at com.sun.opengl.impl.macosx.MacOSXOnscreenGLContext.makeCurrentImpl(MacOSXOnscree
nGLContext.java:57)

at com.sun.opengl.impl.GLContextImpl.makeCurrent(GLContextImpl.java:127)

at com.sun.opengl.impl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:182)

at javax.media.opengl.GLCanvas$DisplayOnEventDispatchThreadAction.run(GLCanvas.java
:298)

at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:199)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)

at jep.MySimpleEventQueue.dispatchEvent(MySimpleEventQueue.java:59)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:2
69)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190
)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:184)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:176)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
java.lang.RuntimeException: java.lang.ClassCastException: com.sun.opengl.impl.macosx.JAWT_MacOSXDrawingSurfaceInfo32

at processing.opengl.PGraphicsOpenGL.requestDisplay(PGraphicsOpenGL.java:172)

at processing.core.PApplet.run(PApplet.java:1562)

at java.lang.Thread.run(Thread.java:613)
Caused by: java.lang.ClassCastException: com.sun.opengl.impl.macosx.JAWT_MacOSXDrawingSurfaceInfo32

at com.sun.opengl.impl.macosx.MacOSXOnscreenGLDrawable.lockSurface(MacOSXOnscreenGL
Drawable.java:177)

at com.sun.opengl.impl.macosx.MacOSXOnscreenGLContext.makeCurrentImpl(MacOSXOnscree
nGLContext.java:57)

at com.sun.opengl.impl.GLContextImpl.makeCurrent(GLContextImpl.java:127)

at com.sun.opengl.impl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:182)

at javax.media.opengl.GLCanvas$DisplayOnEventDispatchThreadAction.run(GLCanvas.java
:298)

at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:199)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)

at jep.MySimpleEventQueue.dispatchEvent(MySimpleEventQueue.java:59)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:2
69)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190
)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:184)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:176)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
Exception in thread "AWT-EventQueue-8" javax.media.opengl.GLException: Attempt to make the same context current twice on thread Thread[AWT-EventQueue-8,4,http://dm.risd.edu/~akhoo/HI/-threadGroup]

at com.sun.opengl.impl.GLContextLock.lock(GLContextLock.java:83)

at com.sun.opengl.impl.GLContextImpl.makeCurrent(GLContextImpl.java:124)

at com.sun.opengl.impl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:182)

at javax.media.opengl.GLCanvas.maybeDoSingleThreadedWorkaround(GLCanvas.java:258)

at javax.media.opengl.GLCanvas.display(GLCanvas.java:130)

at javax.media.opengl.GLCanvas.paint(GLCanvas.java:142)

at sun.awt.RepaintArea.paintComponent(RepaintArea.java:276)

at sun.awt.RepaintArea.paint(RepaintArea.java:241)

at apple.awt.ComponentModel.handleEvent(ComponentModel.java:268)

at apple.awt.MyCCanvas142.handleEvent(MyCCanvas142.java:105)

at java.awt.Component.dispatchEventImpl(Component.java:4144)

at java.awt.Component.dispatchEvent(Component.java:3903)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)

at jep.MySimpleEventQueue.dispatchEvent(MySimpleEventQueue.java:59)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:2
69)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190
)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:184)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:176)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
Re: Argh. OpenGL can only be used in a single appl
Reply #2 - Apr 5th, 2008, 7:03am
 
Hey,

I was about to ask the same issue. In developing OpenProcessing.org, I am having the same problem too. The reason looks like java/browser caches the JOGLLauncher, so the next time it is called, it doesn't work fine. I couldn't make it to work by tweaking the code.
You can test the case by going to two of these urls:
http://www.openprocessing.org/visuals/?visualID=173

http://www.openprocessing.org/visuals/?visualID=172&forceOpenGL=true

Here is the code I am using for <object> code for OpenGL pieces in OpenProcessing.

<!--[if !IE]> -->
<object classid="java:com.sun.opengl.util.JOGLAppletLauncher.class"
           type="application/x-java-applet"
                       codebase="<?=$currentVisual->path?>"
           archive="<?=$currentVisual->url?>,cellnoise.jar,opengl.jar,jogl.jar,core.jar"
           width="<?=$currentVisual->width?>" height="<?=$currentVisual->height?>"
           standby="Loading Processing software..." >
           
<param name="cache_option" VALUE="No">
               <param name="cache_archive" value="<?=$currentVisual->url?>,JOGLAppletLauncher.class,cellnoise.jar,opengl.ja
r,jogl.jar,core.jar" />

<param name="codebase" value="<?=$currentVisual->path?>/">

                   <param name="mayscript" value="true" />
<param name="scriptable" value="true" />
<param name="image" value="loading.gif" />
<param name="boxmessage" value="Loading Processing software..." />
<param name="boxbgcolor" value="#FFFFFF" />
<param name="progressbar" value="true" />

<param name="subapplet.classname" value="<?php $name = explode('.', $currentVisual->url); echo($name[0]);?>" />
<param name="subapplet.displayname" value="<?php $name = explode('.', $currentVisual->url); echo($name[0]);?>" />

<param name="test_string" value="outer" />
<!--<![endif]-->

<object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
codebase="http://java.sun.com/update/1.4.2/jinstall-1_4_2_12-windows-i586.cab"
width="<?=$currentVisual->width?>" height="<?=$currentVisual->height?>"
standby="Loading Processing software..."  >

<param name="code" value="com.sun.opengl.util.JOGLAppletLauncher" />
<param name="archive" value="<?=$currentVisual->url?>,cellnoise.jar,opengl.jar,jogl.jar,core.jar" />
<param name="codebase" value="<?=$currentVisual->path?>/">

<param name="mayscript" value="true" />
<param name="scriptable" value="true" />
<param name="cache_option" VALUE="NO">
                   
<param name="image" value="loading.gif" />
<param name="boxmessage" value="Loading Processing software..." />
<param name="boxbgcolor" value="#FFFFFF" />
<param name="progressbar" value="true" />

<param name="subapplet.classname" value="<?php $name = explode('.', $currentVisual->url); echo($name[0]);?>" />
<param name="subapplet.displayname" value="<?php $name = explode('.', $currentVisual->url); echo($name[0]);?>" />

<param name="test_string" value="inner" />

<p>
<strong>
This browser does not have a Java Plug-in.
<br />
<a href="http://java.sun.com/products/plugin/downloads/index.html" title="Download Java Plug-in">
Get the latest Java Plug-in here.
</a>
</strong>
</p>

</object>

<!--[if !IE]> -->
</object>
<!--<![endif]-->
Re: Argh. OpenGL can only be used in a single appl
Reply #3 - Apr 5th, 2008, 5:13pm
 
Msinan — congratulations on OpenProcessing.org. It's a fantastic site. I dig your warning message about trying to open two OpenGL sketches.

After looking through the source, and trying to play with it, it seems that there's no such problem for JOGLAppletLauncher sketches that aren't based on Processing. Maybe there's something we can fix with PApplet that changes the way that it tries to get a handle on an OpenGL context, initially. If you trace the error down to the code that's first throwing it, it's only because you're trying to lock the GLContext on the same thread where it's already locked. Why this needs to throw an error, instead of just returning happily, is beyond me.

On OpenProcessing, I see that you're looking for a way to export Processing sketches from Eclipse. I know that dhowe is working on an Eclipse plugin that does just that. You should get in touch: http://mrl.nyu.edu/~dhowe/

And, if you're willing, I think it would be nice if it were possible to upload Ruby-Processing sketches to OpenProcessing.org. Let's talk about how to make that happen. Shoot me an email if you're interested: jashkenas atgmaildotcom.
Re: Argh. OpenGL can only be used in a single applet!
Reply #4 - Oct 15th, 2009, 4:34pm
 
Hi all,

I'm trying to use two opengl windows in eclipse:
Code:

import java.awt.Frame;

import processing.core.PApplet;

public class TestProcessingApplet extends PApplet {

// PFrame f;
secondApplet s;

public void setup() {
size(320, 240);
frameRate(15);
new PFrame(); // was PFrame f = new PFrame();
}

public void draw() {
background(255, 0, 0);
fill(0);
rect(20, 20, 50, 50 + frameCount);

}

public class PFrame extends Frame {
public PFrame() {
setBounds(300, 300, 400, 300);
s = new secondApplet();
add(s);
s.init();
setVisible(true); // was show();
}
}

public class secondApplet extends PApplet {
public void setup() {
size(400, 300);
frameRate(15);
}

public void draw() {
background(0);
fill(255);
rect(20, 20, 50, 50 - frameCount);
redraw();
}
}
}


I'm using Mac OS X.
When i draw only one window works ok.
But if I draw two windows i get the error:

Exception in thread "Animation Thread" javax.media.opengl.GLException: Can not destroy context while it is current
    at com.sun.opengl.impl.GLContextImpl.destroy(GLContextImpl.java:176)
    at processing.opengl.PGraphicsOpenGL.allocate(PGraphicsOpenGL.java:201)
    at processing.core.PGraphics3D.setSize(PGraphics3D.java:316)
    at processing.core.PApplet.resizeRenderer(PApplet.java:930)
    at processing.core.PApplet.size(PApplet.java:992)
    at processing.core.PApplet.size(PApplet.java:958)
    at TestProcessingApplet$secondApplet.setup(TestProcessingApplet.java:37)

Can you help me?

Thanks!
Page Index Toggle Pages: 1