Problem 581

Summary: Buglet in OpenGLXViewer prevents programs on MacOSX form exiting correctly
Product: Geant4 Reporter: marcus.h.mendenhall
Component: visualization/OpenGLAssignee: John.Allison
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: other   
Hardware: All   
OS: Other   

Description marcus.h.mendenhall 2004-02-16 15:07:15 CET
On MacOSX, using OpenGL with the OGLIX or OGLSX viewers results in geant4 hanging on exit.  I looked
at the code that destroys an OpenGl context, and at the OpenGL docs, and found the apparent problem.
I think this is probably a latent bug on other platforms, and am not sure why it doesn't show itself
everywhere.  According to the OpenGL docs on glXDestroyContext, this call only destroys a window if it
is not owned by any thread.  The code in the geant4 destructor in G4OpenGLXViewer.cc looks like:


G4OpenGLXViewer::~G4OpenGLXViewer () {
  if (fViewId >= 0) {
    //Close a window from here
    glXDestroyContext (dpy, cx);
    glXMakeCurrent (dpy, None, NULL);
    if (win) XDestroyWindow (dpy, win); // ...if already deleted in
    // sub-class G4OpenGLXmViewer.
    XFlush (dpy);
  }
}

which destroys the window, and then makes it not current.  It seems that switching the two lines so the
window is made non-current first, and then destroyed, is more compatible with the OpenGL docs, and
it does work right on the Macintosh platform.  Thus, switching the destructor to:


G4OpenGLXViewer::~G4OpenGLXViewer () {
  if (fViewId >= 0) {
    //Close a window from here
    glXMakeCurrent (dpy, None, NULL);
    glXDestroyContext (dpy, cx);
    if (win) XDestroyWindow (dpy, win); // ...if already deleted in
    // sub-class G4OpenGLXmViewer.
    XFlush (dpy);
  }
}

fixes the problem on the Mac.  This should be verified to be OK on other platforms, and if it is, should
probably be changed in the source.  If it is not right on other platforms, a conditional to switch the
order of the stements on the Mac could be introduced.
Comment 1 John.Allison 2004-02-17 11:21:59 CET
Works OK on Linux.  Will get into next patch.

Thanks for this in-depth bug fix.  Sorry not to have got to it sooner.