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?

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);

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.

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

_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.

You can also try

_clear87();
_control87(MCW_EM, MCW_EM);

before each frame is rendered, works fine for me…

Originally posted by richardve:
[b]You can also try

_clear87();
_control87(MCW_EM, MCW_EM);

before each frame is rendered, works fine for me…[/b]

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???

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.

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

V-man

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.

Originally posted by Gorg:
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.

And if you are writing a Makefile for the free Borland command line compiler…?