#59 add fgError() exit callback/routine

Easy (28)

Background: for the perl binding of the FreeGLUT library, the use of exit(1) by fgError() results in termination of the perl interpreter itself and cannot be trapped for handling at the script level.

Propose: Allow setting the function to be called by fgError() with the default being the existing implementation. A glutErrorFunc() would allow the perl binding to throw an exception that the interpreter could handle.

Why: The current implementation has no way for multiple routines to access GLUT functionality without jointly coordinating. Even calling glutInit() more than once results in the exit(1) "termination with extreme prejudice"...


  • Chris Marshall

    Chris Marshall - 2010-07-09

    I though of a better/cleaner way to handle this issue without
    breaking the GLUT API. I realized that this change in error
    handling would need to be handled *before* the glutInit()
    call in order to work for glutInit too.

    The idea is to add a command line flag to change the behavior
    of glutInit on errors to not exit but instead return immediately with
    an error message in the argc/argv. If the glutInit completes successfully,
    a standard-ish glutSetOption could be used to control the error handling
    from that point on.

    A bit of a kludge for the first part but it doesn't break existing glutInit
    usage except for the possible change to the argc/argv values but
    this would only happen if the -softinit (or whatever the option is called)
    were passed to the glutInit call.

  • Chris Marshall

    Chris Marshall - 2010-10-15

    After some more thought, I'm not sure it is necessary
    to go to such lengths to implement the "soft fail"
    with glutInit(). Couldn't we just extend the FreeGLUT
    API with a glutInitSoftFail() which is the same as
    glutInit() but it doesn't call exit?

    Once the glutInit() is done, the rest of the support
    for "soft fail" (via a user error handler callback or
    some such) could be done via glutSetOption()
    or adding a glutErrorCallback().


  • Chris Marshall

    Chris Marshall - 2010-10-30

    I've attached a patch for the current freeglut svn (as of Thursday, 28-Oct) which implements the proposed glutInitErrorFunc() and glutInitWarningFunc() calls. Also attached is an example for the prog/demos directory showing a user error handler. The handler implemented in the Error demo just implements the same functionality as the current internal fgError() handler with some verbose output so you know the new code is being called....

  • Diederick C. Niehorster

    • status: open --> closed
  • Chris Marshall

    Chris Marshall - 2012-08-05

    I would be glad to add some docs.

    Any reason the example code attached below could not be added to the source distribution? I think after that never propagated, I never got the chance to finish off the docs. Could have been my lack of familiarity with svn and/or your project protocols.

  • Chris Marshall

    Chris Marshall - 2012-08-05

    I have some docs but have no idea how to propagate them to you. Please advise as I'm not even able to add the new api.php file to this ticket. Probably because I am not a developer.


Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks