Re: Exiting gracefully from (H)GLUT?

I have recently started using the HOpenGL (version 1.01) under Linux running ghc 5.02.1 and have a question. How do I exit my application gracefully (apart from closing the window). In your examples you use
exitWith ExitSuccess
That however causes a:
TestGLUT: fatal error: GLUT_CBWindow_d7Tf: uncaught exception
Not sure whether that may help anyone in debugging, but I didn't use to have this problem until today, so today's changes might be related to the problem: I used to supply the window callback via createWindow, until I naively tried to create a DisplayList, to be passed to the window callback. After wondering just why genLists returned an empty list, I found that I had to move the call to genLists after createWindow. That meant I had to supply an empty window callback to createWindow (return ()), then allocate and fill my DisplayList, and finally register the proper window callback, with displayFunc. Now I also get the error on termination: e:\home\Haskell\hopengl\Tst.exe: fatal error: GLUT_CBWindow_d7TT: uncaught exception The sources mention that it is illegal to unregister a window callback - is registering a new one a problem? Claus PS. I had to twiddle my configuration slightly, to get HOpenGL (great stuff, Sven, btw;) compiled. From the archive, I gather that those missing commas are greencard-related and well-known, though. config: Win2k Cygwin (recent) GHC-5.02.2 (msi) GreenCard 2.03 (msi) HOpenGL-1.01 problems: figuring out how to escape the space in the GreenCard-path:-) --with-green-card="c:/Program\\ Files\GreenCard\green-card.exe" spaces in some .gc files would cause make depend to fail:-( GLUT_State.gc:217 GLUT_Init.gc:76 GLUT_CBWindow.gc:287 adding commas seems to have solved the issue

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

On Fri, Apr 12, 2002 at 12:37:17AM +0200, Wolfgang Thaller wrote:
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 ()
This seems to do the trick. Thanks alot! /Calle

Wolfgang Thaller wrote:
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. [...]
Exactly, I just had a look in the GLUT sources. So the general rule of thumb is: Issue OpenGL calls *after* the first createWindow, never before. This makes sense perfectly: Remember that you could have multiple Windows, so the effect of e.g. setting the current to color depends on the current GLX/OpenGL context. The latter one is created with createWindow, changed with e.g. setWindow, overlay handling, etc. etc. Cheers, S.

As a workaround I suggest importing shutdownHaskellAndExit from the run-time system:
foreign import shutdownHaskellAndExit :: Int -> IO ()
Unfortunately, this will still give me uncaught exceptins using the Haskell "error" function... any ideas to solve this? Thanks, -- Andre W.
participants (5)
-
Andre W B Furtado
-
C.Reinke
-
Calle Lejdfors
-
Sven Panne
-
Wolfgang Thaller