<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://jogamp.org/bugzilla/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.2"
          urlbase="https://jogamp.org/bugzilla/"
          
          maintainer="sgothel@jausoft.com"
>

    <bug>
          <bug_id>669</bug_id>
          
          <creation_ts>2013-01-18 01:36:08 +0100</creation_ts>
          <short_desc>Recursive GLContext makeCurrent() doesn&apos;t work</short_desc>
          <delta_ts>2013-01-20 13:25:43 +0100</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>3</classification_id>
          <classification>JogAmp</classification>
          <product>Jogl</product>
          <component>core</component>
          <version>2</version>
          <rep_platform>All</rep_platform>
          <op_sys>all</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>---</priority>
          <bug_severity>enhancement</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Sven Gothel">sgothel</reporter>
          <assigned_to name="Sven Gothel">sgothel</assigned_to>
          <cc>gouessej</cc>
    
    <cc>sgothel</cc>
    
    <cc>skatejoe1</cc>
          
          <cf_type>---</cf_type>
          <cf_scm_refs>jogl 34687193484b2404d83eebf5d008b71d54e52286</cf_scm_refs>
          <cf_workaround>---</cf_workaround>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2099</commentid>
    <comment_count>0</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2013-01-18 01:36:08 +0100</bug_when>
    <thetext>If issuing makeCurrent()/release() on a GLContext,
the recursive makeCurrent() fails.

The latter is the subsequent where GLContext is already current
and lock-count &gt; 1.

Phenomenon:
  The call succeeds, however, the lock-count is decreased.

  This results in a failing final release() call, where the 
  &apos;inner&apos; recursive release() call already releases the context.

Observed w/:
  - com.ardor3d.example.canvas.JoglAwtExample
  - and JOGL &gt; RC11

Test case will follow up.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2100</commentid>
    <comment_count>1</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2013-01-18 03:40:17 +0100</bug_when>
    <thetext>http://jogamp.org/git/?p=jogl.git;a=commit;h=34687193484b2404d83eebf5d008b71d54e52286

    Culprit:
      GLContext&apos;s makeCurrent() didn&apos;t clear the boolean flag &apos;unlockContextAndSurface&apos;
      in case the context is already current (-&gt; recursion).
      Above case was detected within a code block tailed by a finally block,
      which acted on mentioned flag, i.e. called lock.unlock() and hence decremented the lock count
      even though the method return w/ successful state.
    
      Fixed.
    
    Added debug code:
      GLContext.release() debug code (DEBUG | TRACE_SWITCH),
      recording stack trace of last release() call, which is dumped in case no current was current.
    
    Added 2 unit tests:
      - Simple recursive GLContext makeCurrent()/release() from within GLEventListener&apos;s display().
        Test also validates lock count and lock ownership.
    
      - GLAutoDrawable display() of another GLAutoDrawable
        from within GLEventListener&apos;s display(..).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2104</commentid>
    <comment_count>2</comment_count>
    <who name="david w">skatejoe1</who>
    <bug_when>2013-01-19 09:19:15 +0100</bug_when>
    <thetext>Hi i wanted to try out your new fix, (was debugging my slow app with visualvm and noticing that makeCurrent(), release and makeCurrentWithinLock was called every frame in invokeGLImpl)

This is the output from the new &quot;TraceSwitch&quot; flag:
AWT-EventQueue-0: GLContext.ContextSwitch[makeCurrent.0]: obj 0x400746fe, ctx 0x7fa2140b3400, surf 0x5000012 - &lt;1dc5ee89, 2daf73a4&gt;[count 0, qsz 0, owner &lt;NULL&gt;]
AWT-EventQueue-0: GLContext.ContextSwitch: - setCurrent() - obj 0x400746fe, ctx 0x7fa2140b3400
AWT-EventQueue-0: GLContext.ContextSwitch[makeCurrent.X3]: obj 0x400746fe, ctx 0x7fa2140b3400, surf 0x5000012 - switch - CONTEXT_CURRENT - &lt;1dc5ee89, 2daf73a4&gt;[count 1, qsz 0, owner &lt;AWT-EventQueue-0&gt;]
AWT-EventQueue-0: GLContext.ContextSwitch[release.0]: obj 0x400746fe, ctx 0x7fa2140b3400, surf 0x5000012, inDestruction: false, &lt;1dc5ee89, 2daf73a4&gt;[count 1, qsz 0, owner &lt;AWT-EventQueue-0&gt;]
AWT-EventQueue-0: GLContext.ContextSwitch: - setCurrent() - NULL
AWT-EventQueue-0: GLContext.ContextSwitch[release.X]: obj 0x400746fe, ctx 0x7fa2140b3400, surf 0x5000012 - switch - &lt;1dc5ee89, 2daf73a4&gt;[count 0, qsz 0, owner &lt;NULL&gt;]

from what i understood from the patch it should go into the state
 final GLContext current = getCurrent();
                if (current != null) {
                    if (current == this) {...}

but getCurrent() is always null.

please respond if you need more details!

regards david</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2105</commentid>
    <comment_count>3</comment_count>
    <who name="david w">skatejoe1</who>
    <bug_when>2013-01-20 11:06:53 +0100</bug_when>
    <thetext>this happens using GLCanvas on Ubuntu 12.10

(In reply to comment #2)
&gt; Hi i wanted to try out your new fix, (was debugging my slow app with visualvm
&gt; and noticing that makeCurrent(), release and makeCurrentWithinLock was called
&gt; every frame in invokeGLImpl)
&gt; 
&gt; This is the output from the new &quot;TraceSwitch&quot; flag:
&gt; AWT-EventQueue-0: GLContext.ContextSwitch[makeCurrent.0]: obj 0x400746fe, ctx
&gt; 0x7fa2140b3400, surf 0x5000012 - &lt;1dc5ee89, 2daf73a4&gt;[count 0, qsz 0, owner
&gt; &lt;NULL&gt;]
&gt; AWT-EventQueue-0: GLContext.ContextSwitch: - setCurrent() - obj 0x400746fe, ctx
&gt; 0x7fa2140b3400
&gt; AWT-EventQueue-0: GLContext.ContextSwitch[makeCurrent.X3]: obj 0x400746fe, ctx
&gt; 0x7fa2140b3400, surf 0x5000012 - switch - CONTEXT_CURRENT - &lt;1dc5ee89,
&gt; 2daf73a4&gt;[count 1, qsz 0, owner &lt;AWT-EventQueue-0&gt;]
&gt; AWT-EventQueue-0: GLContext.ContextSwitch[release.0]: obj 0x400746fe, ctx
&gt; 0x7fa2140b3400, surf 0x5000012, inDestruction: false, &lt;1dc5ee89,
&gt; 2daf73a4&gt;[count 1, qsz 0, owner &lt;AWT-EventQueue-0&gt;]
&gt; AWT-EventQueue-0: GLContext.ContextSwitch: - setCurrent() - NULL
&gt; AWT-EventQueue-0: GLContext.ContextSwitch[release.X]: obj 0x400746fe, ctx
&gt; 0x7fa2140b3400, surf 0x5000012 - switch - &lt;1dc5ee89, 2daf73a4&gt;[count 0, qsz 0,
&gt; owner &lt;NULL&gt;]
&gt; 
&gt; from what i understood from the patch it should go into the state
&gt;  final GLContext current = getCurrent();
&gt;                 if (current != null) {
&gt;                     if (current == this) {...}
&gt; 
&gt; but getCurrent() is always null.
&gt; 
&gt; please respond if you need more details!
&gt; 
&gt; regards david</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2106</commentid>
    <comment_count>4</comment_count>
    <who name="Julien Gouesse">gouessej</who>
    <bug_when>2013-01-20 11:37:15 +0100</bug_when>
    <thetext>(In reply to comment #3)
&gt; this happens using GLCanvas on Ubuntu 12.10

Do you reproduce this bug with an existing test case? If not, please provide one. This fix works under GNU Linux. Keep in mind that makeCurrent() may fail, look at the return code. I&apos;m not sure your problem has something to do with this fix.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2107</commentid>
    <comment_count>5</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2013-01-20 13:24:24 +0100</bug_when>
    <thetext>(In reply to comment #2)
&gt; Hi i wanted to try out your new fix, (was debugging my slow app with visualvm
&gt; and noticing that makeCurrent(), release and makeCurrentWithinLock was called
&gt; every frame in invokeGLImpl)
&gt; 

Of course, thats the default behavior.

&gt; 
&gt; from what i understood from the patch it should go into the state
&gt;  final GLContext current = getCurrent();
&gt;                 if (current != null) {
&gt;                     if (current == this) {...}
&gt; 
&gt; but getCurrent() is always null.

Outside of GLEventListener calls it is intended to be null,
otherwise the surface (window, ..) lock would be hold as well.

The fix does fix the use cases as described in the new unit tests
added w/ 34687193484b2404d83eebf5d008b71d54e52286 - please read!

You were probably thinking of an additional feature 
like the Exclusive Context Thread (ECT) as implemented here:
  &lt;http://jogamp.org/git/?p=jogl.git;a=commit;h=224fab1b2c71464826594740022fdcbe278867dc&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2108</commentid>
    <comment_count>6</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2013-01-20 13:25:43 +0100</bug_when>
    <thetext>(In reply to comment #4)
&gt; (In reply to comment #3)
&gt; &gt; this happens using GLCanvas on Ubuntu 12.10
&gt; 
&gt; Do you reproduce this bug with an existing test case? If not, please provide
&gt; one. This fix works under GNU Linux. Keep in mind that makeCurrent() may fail,
&gt; look at the return code. I&apos;m not sure your problem has something to do with
&gt; this fix.

I think it&apos;s only a misunderstanding.

However ..  David, if you think of something else, please provide a full unit test - thx.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>