[HOpenGL] OpenGL/GLUT examples crashing: known problem?

Tim Smith tim at desert.net
Wed Apr 20 08:42:28 EDT 2005

On 2005 Apr 12, Claus Reinke <claus.reinke at talk21.com> wrote:

> there are some opengl debuggers and tracers around - I'm googling for a
> free windows one, mac users seem to have such support provided by apple, 
> other platforms have their own.


Thank you for the response.  I haven't found one yet for XFree86 on

But I did do a number of more experiments.  I have a couple of odd
results that maybe someone can help with.

Here is the strangest one (from my perspective).  I've commented which
objects can be drawn, and which ones crash.  I can't find *any* reason
for this behavior, by looking at the code.

E.g., Sphere' crashes but Cone draws fine.  Looking at the
.../GLUT/Objects.hs, the foreign import statements are basically
identical for the two functions (Cone takes one extra argument).  If
anyone can imagine a way that Cone would succeed but Sphere' would fail,
I'm all ears. :-)

A C program can call glutSolidSphere just fine.  Also, I trimmed out
every unneeded OpenGL-related call; if I put in the usual boilerplate of
setting the projection matrix, etc., it still has the same behavior.

-- cut -----------------------------------------------
import Graphics.UI.GLUT
import qualified System.Environment as Env

main :: IO ()
main = do
    objIndex <- getObjIndex
    createWindow "test"
    displayCallback $= display objIndex

display :: Int -> DisplayCallback
display objIndex = do
    renderObject Solid (objects !! objIndex)
    flush       -- comment this out, and it still crashes on 5-6,8-11

-- This is sloppy, sorry...
getObjIndex :: IO Int
getObjIndex = do
    args <- Env.getArgs
    return (intOfFirstArg args)
        intOfFirstArg [] = 0
        intOfFirstArg (a:_) = read a

objects :: [Object]
objects = [
        Cube 1,                 -- 0:  OK
        Dodecahedron,           -- 1:  OK
        Icosahedron,            -- 2:  OK
        Octahedron,             -- 3:  OK
        Tetrahedron,            -- 4:  OK
        RhombicDodecahedron,    -- 5:  Crash / user error (freeglut)
        Sphere' 1 5 5,          -- 6:  Crash
        Cone 1 1 5 5,           -- 7:  OK
        Cylinder' 1 1 5 5,      -- 8:  Crash / user error (freeglut)
        Torus 0.75 1 5 5,       -- 9:  Crash
        Teapot 1,               -- 10: Crash
        SierpinskiSponge 1      -- 11: Crash / user error (freeglut)
-- cut -----------------------------------------------

The "Crash / user error (freeglut)" comment means that those three
objects crash with the current GLUT code, but return this error when I

objs: user error (unknown GLUT call glutSolidRhombicDodecahedron, check
for freeglut)

There's no configure tests which define that - it's not mentioned
anywhere else besides HsGLUT.c - so I don't know if that's meaningful,
but I thought I would explain it.

There's another class of crashes related to lighting & display lists,
but this is way too long as it is.  I'll stop here, and hope that
someone might be able to suggest a reason for the strange behavior.

Thanks a lot for reading this far!

If you're not part of the solution, you're part of the precipitate.

More information about the HOpenGL mailing list