Dangers of addNotify/removeNotify

Hi folks,

I’m not quite sure about JOGL’s way of
initialising/releasing GLContext in GLCanvas’s
addNotify() and removeNotify() and I
wanna hear what guys have to say.

Currently I’m using JOGL within a Swing
application, containing GLCanvas in a
Swing (!!) container. (Yes PBuffers fail
on me, so…).

I’m using the wonderful Infonode Docking
Windows (IDW) to manage my components.
The trick I’ve had to do to make GLCanvas
fit in nicely with IDW so that it resizes with
all the docking windows is by adding
GLCanvas to a JScrollPane, and implementing
ComponentListener.componentResized().
Obviously I won’t see the scrollbars because
GLCanvas is a heavyweight, so it all works
nicely, albeit with some flickering when I
drag to resize it, but I can live with that.

The problem comes when I press the Maximise
button of the IDW docked window that’s
containing the GLCanvas. It basically minimises
all other docked windows and shows the
current one fullscreen. The way it does it
involves removing its child (which is GLCanvas+
JScrollPane), maximise, then add the child
back. Now this will cause removeNotify()
and addNotify() to be called, destroying the
context and recreating a new one. This is
terrible and crashes my app (I still haven’t
figured out why). So I’ve had to override
addNotify() and removeNotify() to prevent
this from happening.

Now given my use case is not very unusual,
I’m wondering if using addNotify/removeNotify
to manage the context is really a good
approach. Let’s discuss…

.rex

addNotify / removeNotify are the only hooks the AWT provides in which we can correctly destroy and recreate the OpenGL context, given that the underlying native widget is being destroyed.

There may still be bugs in JOGL’s handling of these events, although one bug reported recently turned out to be a driver bug (wasn’t reproducible on other machines / graphics cards). Additionally, it may be the case that when the GLCanvas is part of a complicated widget hierarchy things get more complicated. If you can boil down your app into a small test case please file a bug with the JOGL Issue Tracker.