can not create CLGLObject (random)

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

can not create CLGLObject (random)

The.Scotsman
Standard display() scenario:

if(!sceneInitialized) {
  GL2 gl = drawable.getGL().getGL2();
  gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);
  long length = buffLen * GLBuffers.SIZEOF_FLOAT;

  gl.glGenBuffers(1, VBOidV, 0);
  gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, VBOidV[0]);
  gl.glBufferData(GL2.GL_ARRAY_BUFFER, length, vBuff, GL2.GL_STATIC_DRAW);

...repeat for normals...

  gl.glDisableClientState(GL2.GL_VERTEX_ARRAY);

  gl.glFinish();
  System.out.println("clContext = " + clContext);
  clBuffer = clContext.createFromGLBuffer(VBOidV[0], length, CLGLBuffer.Mem.READ_ONLY);

  sceneInitialized = true;
}

The graphics for this display beautifully.
However, the createFromGLBuffer crashes randomly.

Actually, not completely randomly.
I load a new "model" and call canvas.display() (i.e. repaint-on-demand)
clContext does not change.
createFromGLBuffer throws an exception about 2/3 the time.

com.jogamp.opencl.CLException$CLInvalidGLObjectException: can not create CLGLObject from #1 [error: CL_INVALID_GL_OBJECT]

This seems like some kind of timing/threading problem.
(canvas.display() appears to be threaded)

The jogamp use guide isn't much help here - the section under "AWT Multithreading Issues" starts with "Below statements incorrect!"

Any clue as to how to approach this?
Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: can not create CLGLObject (random)

The.Scotsman
After suffering with this for weeks, it looks like I finally stumbled upon a solution.
Simply added 'glautodrawable.getContext().makeCurrent()' before 'createFromGLBuffer' and everything is copacetic.
And all along I thought the context was current inside the 'display' method...
Reply | Threaded
Open this post in threaded view
|

Re: can not create CLGLObject (random)

gouessej
Administrator
It's quite a strange solution as you're right, the context should be current in GLCanvas.display(). But when you call repaint "on-demand", it might be not yet current. Why not using invoke(GLRunnable) instead?
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: can not create CLGLObject (random)

Sven Gothel
Administrator
In reply to this post by The.Scotsman
On 06/16/2012 12:16 AM, The.Scotsman [via jogamp] wrote:

> Standard display() scenario:
>
> if(!sceneInitialized) {
>   GL2 gl = drawable.getGL().getGL2();
>   gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);
>   long length = buffLen * GLBuffers.SIZEOF_FLOAT;
>
>   gl.glGenBuffers(1, VBOidV, 0);
>   gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, VBOidV[0]);
>   gl.glBufferData(GL2.GL_ARRAY_BUFFER, length, vBuff, GL2.GL_STATIC_DRAW);
>
> ...repeat for normals...
>
>   gl.glDisableClientState(GL2.GL_VERTEX_ARRAY);
>
>   gl.glFinish();
>   System.out.println("clContext = " + clContext);
>   clBuffer = clContext.createFromGLBuffer(VBOidV[0], length, CLGLBuffer.Mem.READ_ONLY);
>
>   sceneInitialized = true;
> }
>
>
> The graphics for this display /beautifully/.
> However, the *createFromGLBuffer* crashes randomly.
>
> Actually, not completely randomly.
> I load a new "model" and call *canvas.display()* (i.e. repaint-on-demand)
> *clContext* does not change.
> *createFromGLBuffer* throws an exception about 2/3 the time.
>
> com.jogamp.opencl.CLException$CLInvalidGLObjectException: can not create CLGLObject from #1 [error: CL_INVALID_GL_OBJECT]
>
>
> This seems like some kind of timing/threading problem.
> (*canvas.display()* appears to be threaded)
>
> The jogamp use guide isn't much help here - the section under "AWT
> Multithreading Issues" starts with "Below statements incorrect!"
>
> Any clue as to how to approach this?
Could be related to:

http://forum.jogamp.org/stuck-in-Processing-with-with-any-JOGL-release-RC6-Mac-tp4025519p4025528.html

https://jogamp.org/bugzilla/show_bug.cgi?id=606

Will take care of this tomorrow.

Pls track the above bug report.
When I claim it fixed, pls retest and reply.

~Sven

> Thanks.
>


signature.asc (910 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: can not create CLGLObject (random)

The.Scotsman
I was a little premature with the workaround - it still throws that exception from time to time.
In addition, it throws another exception (GLException: XXX) on every program exit (via GLContextImpl.destroy)

Removed the "workaround", and replaced canvas.display() with:

  GLRunnable glr = new GLRunnable() {
    public boolean run(GLAutoDrawable d) {
      return false;
    }
  };
  canvas.invoke(false, glr);

The code looks "better", but the problem persists.

I will try Sven's fix when it's available via a new release (building one is a little outside my mandate).
But I should mention that I'm on Win7 x64 ATI.