Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Disabling Floating Point Exceptions

  1. #1
    Intern Newbie
    Join Date
    May 2000
    Location
    Mesa, Arizona USA
    Posts
    30

    Disabling Floating Point Exceptions

    I stumbled across this entry in my compiler documentation (Borland C++ Builder).

    "...It is recommended that you disable all floating-point exceptions when using OpenGL to render 3D graphics. To do this, call Set8087CW(0x133f) in your main form’s OnCreate event before calling any OpenGL functions."

    Anyone have any experience using this?

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Oct 2000
    Posts
    531

    Re: Disabling Floating Point Exceptions

    MSVC ignores floating point exceptions by default, BCB doesn't..

    Just include float.h en put this line in your code (before calling any gl functions):

    _control87(MCW_EM, MCW_EM);

  3. #3
    Junior Member Newbie
    Join Date
    May 2001
    Posts
    24

    Re: Disabling Floating Point Exceptions

    It's not a problem if you run outside the Borland IDE, but the IDE halts the program
    occasinally with an fp exception if you don't
    disable them. Annoying, nothing else.

  4. #4
    Intern Newbie
    Join Date
    May 2000
    Location
    Mesa, Arizona USA
    Posts
    30

    Re: Disabling Floating Point Exceptions

    Thanks for the info.

    Any idea as to the source of the floating point exceptions? They don't seem to be originating in my code. Is it possibly a manifestation of a crappy MS implementation? Do any of you Linux/Unix/SGI guys have these issues?

    Mike

  5. #5
    Intern Contributor
    Join Date
    May 2001
    Location
    Warsaw Poland
    Posts
    73

    Re: Disabling Floating Point Exceptions

    _control87(...) doesn't prevent BC++ from stopping execution on some FP exceptions
    (that F****** dialogs like "sqrt domain error"), so I recommend also this:

    #include <math.h>
    int _matherr(struct _exception *e)
    {
    e->retval = 0;
    return 1;
    }

    I dont know why, but it doesnt work if you link this code from library, so I always put it in every project.

  6. #6
    Advanced Member Frequent Contributor
    Join Date
    Oct 2000
    Posts
    531

    Re: Disabling Floating Point Exceptions

    You can also try

    _clear87();
    _control87(MCW_EM, MCW_EM);

    before each frame is rendered, works fine for me..

  7. #7
    Advanced Member Frequent Contributor marcus256's Avatar
    Join Date
    Aug 2001
    Location
    Sweden
    Posts
    853

    Re: Disabling Floating Point Exceptions

    Originally posted by richardve:
    You can also try

    _clear87();
    _control87(MCW_EM, MCW_EM);

    before each frame is rendered, works fine for me..
    Can anyone verify this? I am looking to include Borland support for GLFW ( http://hem.passagen.se/opengl/glfw/ ) in the next release, and I thought it would be a good idea to make it part of the framework so that people do not have to care about this when compiling GLFW programs for Borland.

    It sounds strange that it should be done every frame to prevent errors - wouldn't it work if we just do it before creating the GL context? Or is there some debugger or something that goes in and resets the FP register every now and then???

  8. #8
    Advanced Member Frequent Contributor
    Join Date
    Oct 2000
    Posts
    531

    Re: Disabling Floating Point Exceptions

    I was a bit wrong in that post, you can leave out _clear87() and you only have to call _control87(..) before calling any GL functions, not every frame

    IIRC there's also a section about this in the OGL FAQ.

  9. #9
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,421

    Re: Disabling Floating Point Exceptions

    I've never understood this one. What exactly is causing the exception? Perspective divide perhaps?

    V-man
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

  10. #10
    Advanced Member Frequent Contributor
    Join Date
    Feb 2000
    Posts
    662

    Re: Disabling Floating Point Exceptions

    To disable floating point exceptions cleanly, you can simply go into project options and uncheck float point exception. If I remember well, it is in the linker tab.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •