GLEventListener init() not being called

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

GLEventListener init() not being called

Dolda2000
Did something change with the GLEventListener "contract" between 2.0.2 and 2.1.2? I just upgraded, and found that on some configurations, display() is being called before init() or reshape() are called. Needless to say, this crashes the program, since it never gets to carry out its initialization.

I tried setting a flag once init() and reshape() have been called and make display() simply return if the flag hasn't been set. However, it turns out that they aren't being called at all, ever, leading to nothing being drawn.

What's up with that? Is there something wrong I might be doing to cause this behavior? I'm using a GLCanvas, and I add my GLEventListener during the constructor.
Reply | Threaded
Open this post in threaded view
|

Re: GLEventListener init() not being called

jmaasing
I don't think it should have changed. The best thing you can do is write a minimal 'test' app that displays the problem so it is easy to reproduce.
Reply | Threaded
Open this post in threaded view
|

Re: GLEventListener init() not being called

Sven Gothel
Administrator
On 11/02/2013 11:48 AM, jmaasing [via jogamp] wrote:
> I don't think it should have changed. The best thing you can do is write a
> minimal 'test' app that displays the problem so it is easy to reproduce.
>

Yes, it not only should have not changed - AFAIK, it has not being changed.

However, if one of the many changes created such side-effect,
please show us a simple unit test and add it to a bug report.

Please note: None of our many unit tests would work,
if display(..) would be called w/o init(..) once first.

~Sven



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

Re: GLEventListener init() not being called

Dolda2000
Sven Gothel wrote
On 11/02/2013 11:48 AM, jmaasing [via jogamp] wrote:
> I don't think it should have changed. The best thing you can do is write a
> minimal 'test' app that displays the problem so it is easy to reproduce.
>

Yes, it not only should have not changed - AFAIK, it has not being changed.
Ah, indeed, I'm sorry. I was merely taken by surprise by the fact that init() is called from without my ThreadGroup, which handles exceptions. That being the case, init() simply didn't get to finish because of a thus hidden exception in a new part of that code that I had added.

(Specifically, I though glGet(GL_MAJOR_VERSION) would be available everywhere, but apparently it isn't.)
Reply | Threaded
Open this post in threaded view
|

Re: GLEventListener init() not being called

Dolda2000
On second thought, however, isn't it arguable that JOGL shouldn't be calling display() in case init() or reshape() terminated abnormally?
Reply | Threaded
Open this post in threaded view
|

Re: GLEventListener init() not being called

Sven Gothel
Administrator
On 11/02/2013 01:02 PM, Dolda2000 [via jogamp] wrote:
> On second thought, however, isn't it arguable that JOGL shouldn't be calling
> display() in case init() or reshape() terminated abnormally?

Make it more robust you mean ?
Sounds reasonable, have to check the 'costs'.

(GLEL == GLEventListener)

I.e. we would need to:
 - catch the exception (guess we do at some point)
 - move the GLEL back to not-initialized state - or -
   remove it from GLEL list.
 - not calling display ..

This would mainly help development .. hmm,
however .. you got the exception in the end.

Unsure about this. Usually we follow the 'fail fast' approach
throwing an exception.

In case of unpredicted or not so determined states within one GLEL,
one might want to deal w/ failing init(..) methods.
But then again - you could handle them inside your own GLEL.

Shouldn't we assume well behaving GLELs ?

Yes, we may need to discuss this a bit more.

~Sven



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

Re: GLEventListener init() not being called

Dolda2000
Sven Gothel wrote
Unsure about this. Usually we follow the 'fail fast' approach
throwing an exception.
Ah, but you wouldn't necessarily have to catch the exception and discard it. I don't know just how the code that calls the GLEL methods look like, but I would imagine a scheme similar to this:

private Throwable error = null;

void aroundInit(GLEventListener l) {
    try {
        l.init()
    } catch(Throwable t) {
        this.error = t;
        throw(t);
    }
}

void aroundDisplay(GLEventListener l) {
    if(error != null)
        throw(new GLException("init never completed", t));
    l.display()
}

No?
Reply | Threaded
Open this post in threaded view
|

Re: GLEventListener init() not being called

jmaasing
Personally (as a matter of taste) I think putting some documentation in there saying display will be called even if init throws exceptions would be better.

It is pretty easy to make a listener like below in the JOGL-"client":

class RobustGLEventListener implements GLEventListener {
   private final GLEventListener delegate ;
   private final AtomicBoolean initialized = new AtomicBoolean(false) ;

   public RobustGLEventListener(GLEventListener delegate) {
     this.delegate = checkNotNull(delegate) ;
  }

  @Override
  public void display() {
    if (this.initialized.get()) {
       this.delegate.display();
...
Reply | Threaded
Open this post in threaded view
|

Re: GLEventListener init() not being called

Sven Gothel
Administrator
On 11/03/2013 03:02 PM, jmaasing [via jogamp] wrote:

> Personally (as a matter of taste) I think putting some documentation in there
> saying display will be called even if init throws exceptions would be better.
>
> It is pretty easy to make a listener like below in the JOGL-"client":
>
> class RobustGLEventListener implements GLEventListener {
>    private final GLEventListener delegate ;
>    private final AtomicBoolean initialized = new AtomicBoolean(false) ;
>
>    public RobustGLEventListener(GLEventListener delegate) {
>      this.delegate = checkNotNull(delegate) ;
>   }
>
>   @Override
>   public void display() {
>     if (this.initialized.get()) {
>        this.delegate.display();
> ...
>
I am convinced, pls file a bug report
  'Make GLEventListener Robost, i.e. no reshape nor display if init fails'

Q: Besides not calling those methods .. how shall we behave then ?
  - Remove the GLEL ?
  - Try init(..) etc next time ?
  - ??


~Sven



signature.asc (911 bytes) Download Attachment