#18 2.0.0 Spurious Joystick and Draw events for closed window

closed-fixed
nobody
moderate (59)
5
2003-11-11
2003-09-15
Nigel Stewart
No

>The function fgCloseWindows is used at the end
>> of each pass of glutMainLoopEvent to destroy
>> all the windows in the WindowsToDestroy list
>> to avoid destroying windows while their
>> callback handlers are still executing.
>>
>> However, if the handler calls glutDestroyWindow
>> as part of a timer or joystick handler,
>> FreeGLUT may still send joystick or draw events
>> to the window.

> Yes, this is one of the many known side effects of
> deffering the destruction of windows until later.
> glut destroyed windows immediatly. freeglut used
> to do so as well. I have been contemplating reverting
> this change. Another option is having
> glutDestroyWindow() unset all callbacks and zero
> the window's ID.

I would suggest clearing all the callbacks for a window
in fgAddToWindowDestroyList. This would ensure that
an application will receive no more events (death via
glutDestroyWindow() is final!) once the window is
destroyed.

However, this can certainly wait until RC6 or 2.0.0
is resolved.. :-)

Discussion

  • Nigel Stewart
    Nigel Stewart
    2003-09-22

    Logged In: YES
    user_id=338692

    I have also observed a variation of this with RC6
    on Windows in the lorenz demo program. If the
    program is closed by pressing ESC, it is fine.
    If the probelm is clocked by clicking the top-right
    "close" button, the debug build fails an assertion
    (the release build simply crashes):

    Assertion failed: fgStructure.Window != NULL, file
    m:\tmp\freeglut-2.0.0\src\fre
    eglut_display.c, line 48

    Apparently, the timer callback has been processed
    by FreeGLUT even though there exists no window.

    Perhaps the timer even queue should be cleared
    explicitly once the last window is closed.

     
  • Nigel Stewart
    Nigel Stewart
    2003-09-30

    Logged In: YES
    user_id=338692

    Suggested change to freeglut_structure.c, around line 226:

    /*
    * Check if the window is the current one...
    */
    if ( fgStructure.Window == window )
    fgStructure.Window = NULL;

    /*
    * Clear all window callbacks to NULL
    *
    * Now that this window is dead, ensure that any registered
    * callback handlers are immediately forgotten and never
    * become "dangling" pointers.
    */
    memset(&window->Callbacks,0,sizeof(SFG_WindowCallbacks));

    -----------------

    The memset() is a short-hand way of setting each window
    callback to NULL.

     
  • Nigel Stewart
    Nigel Stewart
    2003-09-30

    • summary: RC5 Spurious Joystick and Draw events for closed window --> 2.0.0 Spurious Joystick and Draw events for closed window
     
  • Richard Rauch
    Richard Rauch
    2003-10-26

    Logged In: YES
    user_id=854844

    As hashed out on the list, ANSI C does not guarantee that
    NULL pointers are pointers with all-bits-zero. So memset()
    does not give you what you are hoping for in the proposed
    solution.

    The present freeglut state structure requires a bunch of
    separate assignments in order to do it legally. Another
    safe way to do it is to use an array (enum or #define
    symbolic constants for indexing the array). Then you can
    loop over the array of function-pointers, passing in
    explicit NULLs. The downside, of course, is that that
    requires touching just about everything that uses a callback
    (or sets one).

     
  • Richard Rauch
    Richard Rauch
    2003-10-26

    Logged In: YES
    user_id=854844

    As hashed out on the list, ANSI C does not guarantee that
    NULL pointers are pointers with all-bits-zero. So memset()
    does not give you what you are hoping for in the proposed
    solution.

    The present freeglut state structure requires a bunch of
    separate assignments in order to do it legally. Another
    safe way to do it is to use an array (enum or #define
    symbolic constants for indexing the array). Then you can
    loop over the array of function-pointers, passing in
    explicit NULLs. The downside, of course, is that that
    requires touching just about everything that uses a callback
    (or sets one).

     
  • Nigel Stewart
    Nigel Stewart
    2003-11-05

    Logged In: YES
    user_id=338692

    Without digging into the extreme fine-print of the various
    revisions of the ANSI C specification, I regard the memset
    approach preferable to the alternatives suggested on-list
    and here also. I don't mind it being marked as
    /* TODO - This is not strictly ANSI-C code */ or similar,
    but I would like to see the issue resolved as a matter of
    priority (FreeGLUT is not usable with my app) rather than
    agonising over the weaker aspects of the C programming
    language.

     
  • Richard Rauch
    Richard Rauch
    2003-11-07

    Logged In: YES
    user_id=854844

    Done (with an array notation).

    Does this solve your problem, as was hoped?

     
  • Richard Rauch
    Richard Rauch
    2003-11-07

    Logged In: YES
    user_id=854844

    Done (with an array notation).

    Does this solve your problem, as was hoped?

     
  • Nigel Stewart
    Nigel Stewart
    2003-11-11

    • status: open --> closed-fixed