Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (549)
Games in Android Showcase (139)
games submitted by our members
Games in WIP (593)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  ...jogl.GLException: Unable to lock surface  (Read 2516 times)
0 Members and 1 Guest are viewing this topic.
Offline karmaGfa

Junior Devvie


« Posted 2004-04-25 06:13:24 »

I made a class which extends a Frame, where I put an instance of the GLCanvas.

When I create an instance of this class from the main function (i.e. from the main thread), there is no problem.

When I create an instance of this class from the event thread (i.e. when the use push a button or something like that), the instruction "canvas.setSize(320, 200);" in the constructor of my class throws an exeption.

When I comment out the "setSize(320, 200);", there is no problem but my frame is zero sized and the user need to resize it manually :-(

The setSize() function cause a reshape() call on the canvas object, which cause this execption to be thrown. Since I don't call the reshape function myself, the propagation of this exception to the level of the setSize() function is a bug.

Here is the trace of the exception : Unable to lock surface





     at java.awt.Component.setBounds(

     at java.awt.Component.resize(

     at java.awt.Component.setSize(

     at jardin.scene.OpenGLFrame.<init>(

     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

     at sun.reflect.NativeConstructorAccessorImpl.newInstance(

     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(

     at java.lang.reflect.Constructor.newInstance(

     at java.lang.Class.newInstance0(

     at java.lang.Class.newInstance(

     at jardinier.classBrowserPanel.ClassBrowserPanel.instantiateSelectedTreeNode(


Here is the source of the constructor of my Frame class :

public class OpenGLFrame
       extends Frame

   protected GLCanvas canvas;
   protected Scene currentScene = new Scene();

   public OpenGLFrame()
       GLCapabilities capabilities = new GLCapabilities();
       canvas = GLDrawableFactory.getFactory().createGLCanvas(capabilities);
       canvas.setSize(320, 200);



Vincent Cantin

<a href="">Le Moulin Studio</a> - MMO Technologies and Services.
Offline karmaGfa

Junior Devvie


« Reply #1 - Posted 2004-04-25 06:50:13 »

I just tried with the nightly build, and the problem is still there.

<a href="">Le Moulin Studio</a> - MMO Technologies and Services.
Offline milvich

Senior Newbie

Java games rock!

« Reply #2 - Posted 2004-04-25 13:09:02 »

My guess is that the GL Context hasn't been set up yet. I believe that JOGL delays the actual creation of the context until first display. So the reshape is happening before the context is created.

Why don't you try setting the size before adding the GLCanvas?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Ken Russell

JGO Coder

Java games rock!

« Reply #3 - Posted 2004-04-26 01:08:24 »

Could you boil this down into a test case and file an issue on the Issue Tracker page linked off the JOGL web page?
Offline karmaGfa

Junior Devvie


« Reply #4 - Posted 2004-04-26 14:25:32 »

Could you boil this down into a test case and file an issue on the Issue Tracker page linked off the JOGL web page?

Yes, I will do that soon.

<a href="">Le Moulin Studio</a> - MMO Technologies and Services.
Offline robdarich

Senior Newbie

Java games rock!

« Reply #5 - Posted 2004-06-21 17:31:17 »

I am having a similar problem and was wondering if anyone has come up with a solution to this.  I have updated with the nightly build and that didn't help.  The exception only occurs on my windows box.  The same application runs fine on the mac.  here is part of the exception trace: Unable to lock surface Unable to lock surface
at java.awt.Component.setBounds(

this comes as the result of a user pressing a button which creates a new instance of a Jwindow extended class which than adds a jogl canvas to its content pane.  the excetion occurs at this line:


thanks for any help
Offline cgunn

Senior Newbie

« Reply #6 - Posted 2004-06-22 09:26:12 »

├čI am also currently struggling with an exception of this type.  The JOGL User's Guide indicates that it has to do the with multi-threaded environment of Java interacting with the C-origins of OpenGL:
(the User's Guide is available at*checkout*/jogl/doc/userguide/index.html?rev=HEAD&content-type=text/html).  Here's a relevant quote:

"Both of these models (repaint-on-demand and repaint continually) still require the user to think about which thread keyboard and mouse events are coming in on, and which thread is performing the OpenGL rendering. OpenGL rendering may not occur directly inside the mouse or keyboard handlers, because the OpenGL context for the drawable is not current at this point (hence the warning about storing a GL object in a field, where it can be fetched and accidentally used by another thread). However, a mouse or keyboard listener may invoke GLDrawable.display().

"It is generally recommended that applications perform as little work as possible inside their mouse and keyboard handlers to keep the GUI responsive. However, since OpenGL commands can not be run from directly within the mouse or keyboard event listener, the best practice is to store off state when the listener is entered and retrieve this state during the next call to GLEventListener.display()."

So, the problem referred to in this thread might be avoided by following the advice given here.  That is, store off state in the keyboard and mouse listeners, but don't do anything that will directly cause display of a GLDrawable on the event-handling thread.

Unfortunately, there are still situations where it is hard to avoid having display called from the wrong thread (for example, an IDE that instantiates instances of Java objects: when that Java object contains a GLDrawable, the wrong thread may inadvertantly be called to display it -- at least that what seems to be causing the exceptions I'm encountering).  

Hope this helps.

Thanks to whoever wrote the User's Guide.  And, if you're reading this, what about updating it with any new and useful developments in the themes it deals with?
Offline GKW

Senior Devvie

Revenge is mine!

« Reply #7 - Posted 2004-06-22 14:14:41 »

Make sure your window is visible before you call setBounds.  The canvas needs to be attached to the screen before you can work with it.
Offline robdarich

Senior Newbie

Java games rock!

« Reply #8 - Posted 2004-06-22 14:26:11 »

Make sure your window is visible before you call setBounds.  The canvas needs to be attached to the screen before you can work with it.

yes, that seems to work, although it is odd that this is not the case when the code is run on the mac.
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.


Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Archive (20 views)
2015-01-29 04:26:08

theagentd (21 views)
2015-01-28 15:33:52

GamerIDGoesHere (29 views)
2015-01-27 01:23:23

GamerIDGoesHere (31 views)
2015-01-27 01:22:15

CopyableCougar4 (37 views)
2015-01-27 00:34:41

CopyableCougar4 (23 views)
2015-01-26 04:47:56

Olo (17 views)
2015-01-25 21:26:00

Olo (23 views)
2015-01-25 18:44:22

Robo11 (39 views)
2015-01-25 06:14:26

basil_ (33 views)
2015-01-17 22:29:32
2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!