[HOpenGL] Re: Exiting gracefully from (H)GLUT?

Wolfgang Thaller wolfgang.thaller@gmx.net
Fri, 12 Apr 2002 00:37:17 +0200 (MEST)


Calle Lejdfors wrote:
> exitWith ExitSuccess
> 
> That however causes a:
> 
> TestGLUT: fatal error: GLUT_CBWindow_d7Tf: uncaught exception

This is because GHC implements exit using an exception that is caught
outside the main program - GHC's implementation of exitWith just doesn't work with
callbacks.

As a workaround I suggest importing shutdownHaskellAndExit from the run-time
system:

foreign import shutdownHaskellAndExit :: Int -> IO ()

You could also use the plain old "exit" from the C standard library, but
that breaks GHC's profiler. I don't know what other issues (concurrency?) are
involved with this workaround, but I think it has been discussed on this list
or on ghc-users a while ago.

C. Reinke wrote:
> [...] I found that I
> had to move the call to genLists after createWindow.

I'd expect that, because most (all?) versions of GLUT don't initialize the
OpenGL context until the window has actually been created.
There is a version of GLUT (I don't remember which, I think it was an
"exotic" one - MacOS or BeOS) that does it even later, only when the main loop is
actually started, so that display list generation is impossible until the
first call to display.


> The sources mention that it is illegal to unregister a
> window callback -  is registering a new one a problem?

Changing window callbacks is perfectly OK as far as GLUT is concerned, and
I've successfully done it with HOpenGL.


Regards,
 Wolfgang

-- 
GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net