#153 win32: hang after main window close

v3.0.0
open
nobody
GLUT (25)
5
2006-11-10
2006-11-10
David Murmann
No

After the main GLUT window is closed the process stays
alive.

This is actually documented behavior (in the top
comment in OpenGL/GLUT/special.py), but it differs from
PyOpenGL 2, therefore I think it should be fixed.

Discussion

  • David Murmann
    David Murmann
    2006-11-10

    • milestone: --> v3.0.0
     
  • Logged In: YES
    user_id=34901

    Weird thing is that I can't see *how* PyOpenGL 2.x fixed it
    when I spelunk through the code. It seems to have "just
    worked". I've added code to "fix" it, basically I start a
    .5s timer in glutMainLoop() that checks for a NULL context
    and kills the process if it's discovered.

    Anyway, give it a try with latest CVS and let me know if
    it's suitable for you (or if you have a better approach in
    mind).

     
  • David Murmann
    David Murmann
    2006-11-13

    Logged In: YES
    user_id=1455846

    Yeah, this works, i tried a very similar fix (although i did
    it in my app), but it seems very much like a hack.

    It seems the question is not how 2.x fixed it (apparently it
    didn't address this altogether), but what does 3.x wrong to
    stall the process. A normal GLUT program doesn't need to do
    this, so why should a python wrapper need this check? Looks
    to me like somewhere something should be cleaned up, or
    weakref'd or something similar to allow the process to die,
    but i couldn't find anything yet...

     
  • Thomas Heller
    Thomas Heller
    2006-11-13

    Logged In: YES
    user_id=11105

    The reason for the process staying alive is that on Windows
    glut.h contains special code in the header file that must be
    reimplemented in ctypes. The "glutCreateWindow", for
    example, is redefined like this:

    #if defined(_WIN32) && !defined(GLUT_DISABLE_ATEXIT_HACK)
    GLUTAPI int APIENTRY __glutCreateWindowWithExit(const char
    *title, void (__cdecl *exitfunc)(int));
    #ifndef GLUT_BUILDING_LIB
    static int APIENTRY glutCreateWindow_ATEXIT_HACK(const char
    *title) { return __glutCreateWindowWithExit(title, exit); }
    #define glutCreateWindow glutCreateWindow_ATEXIT_HACK
    #endif

    In other words: Instead of calling the glutCreateWindow
    function you must call __glutCreateWindowWithExit, and pass
    a pointer to the standard 'exit' function as additional last
    parameter.

    I have attached a patch which demonstrates how this could be
    fixed for the glutCreateWindow() function, glutInit() and
    glutCreateMenu() must probably be changed as well. The
    patch is not really correct, thought, since it hardcodes the
    C library dll name as 'msvcr71', which may not be correct,
    depending on how Python itself was built.

    PS: Seems I'm not allowed to attach a patch. Here it is (to
    be applied to OpenGL\raw\GLUT\__init__.py):

    --- __init__.py~ Mon Nov 13 10:54:38 2006
    +++ __init__.py Mon Nov 13 11:03:35 2006
    @@ -159,15 +159,29 @@
    argNames=('window', 'x', 'y', 'width', 'height'),
    )

    +import os

    -# /usr/include/GL/freeglut_std.h 398
    -glutCreateWindow = platform.createBaseFunction(
    - 'glutCreateWindow', dll=platform.GLUT, resultType=c_int,
    - argTypes=[STRING],
    - doc='glutCreateWindow( STRING(title) ) -> c_int',
    - argNames=('title',),
    -)
    +if os.name == "nt":
    + __glutCreateWindowWithExit = platform.createBaseFunction(
    + '__glutCreateWindowWithExit',
    dll=platform.GLUT, resultType=c_int,
    + argTypes=[STRING, c_void_p],
    + doc='glutCreateWindow( STRING(title) ) -> c_int',
    + argNames=('title',),
    + )

    + libc = CDLL("msvcr71")
    +
    + def glutCreateWindow(title):
    + __glutCreateWindowWithExit(title, libc.exit)
    +
    +else:
    + # /usr/include/GL/freeglut_std.h 398
    + glutCreateWindow = platform.createBaseFunction(
    + 'glutCreateWindow', dll=platform.GLUT,
    resultType=c_int,
    + argTypes=[STRING],
    + doc='glutCreateWindow( STRING(title) ) -> c_int',
    + argNames=('title',),
    + )

    # /usr/include/GL/freeglut_std.h 442
    glutDestroyMenu = platform.createBaseFunction(

     
  • David Murmann
    David Murmann
    2006-11-13

    fix to special.py

     
    Attachments
  • David Murmann
    David Murmann
    2006-11-13

    Logged In: YES
    user_id=1455846

    Very nice, thanks for the input! I attached a patch that
    does this in GLUT/special.py (as the comment at the top of
    raw/GLUT/__init__.py says "do not edit"). My patch also
    doesn't hardcode msvcr71 but uses sys.exit with a ctypes
    callback instead. btw, is it preferred to check on os.name,
    instead of sys.platform? i usually use the latter...

     
  • David Murmann
    David Murmann
    2006-11-13

    Logged In: YES
    user_id=1455846

    Second version of the patch does this for all
    __glut*WithExit functions.

     
  • David Murmann
    David Murmann
    2006-11-13

    2nd version

     
    Attachments
  • David Murmann
    David Murmann
    2006-11-13

    Logged In: YES
    user_id=1455846

    Arr, too quick with the posting, glutCreateMenu is probably
    a bit more complicated, because its already overwritten in
    special.py, this needs some more attention.