OpenGL crashing when clipping


I have modeled a soccerfield and now I wanted to move a camera from one end of the field to the other end. Now, when the camera gradually moves on to the field the prog crashes with this error:
'Project ‘blaat.exe’ raised exception class EInvalidOp with message ‘Invalid Floating Point Operation’.

It crashes at the point where my nearest polygon (the field) hits zNear. (zNear and zFar are both positive)

what’s going on?

It is possible that your view matrix is screwy (for example, having a camera focus on its own position, leading to floating point trouble-up-mill).

Are you using gluLookAt?

No, I don’t use gluLookAt (yet). But have a look at my sourcecode, maybe you see something wrong with it:

// Here’s the projection part

glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);		glLoadIdentity();		
gluPerspective(26.0, (GLfloat)width/(GLfloat)height,5000.0f,35000.0f);
glMatrixMode(GL_MODELVIEW);		glLoadIdentity();		

// Initialization settings
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClearDepth(1.0f); glDepthFunc(GL_LESS); glEnable(GL_DEPTH_TEST);

// And here is the rendering loop (just for testing purposes only, I know its not nicely coded)
double afstandMiddenstip = -12000;
time_t t1 = time(0);
for (int i = 1; i <= 6000; i++)
glTranslatef (-v.Breedte()/2.0, 0.0, afstandMiddenstip);
glRotatef (hoek, 1.0, 0.0, 0.0);
glTranslatef (0.0, -v.Lengte()/2.0, 0.0);

       afstandMiddenstip += 10;

Hope you can find something. By the way, in the mean time I recalled some command for disabling FPU-exceptions, ‘Set8087’. I havent figured out yet how to use this, but could that be the solution to my problem?

[This message has been edited by Quirus (edited 10-31-2002).]

Well, i didnt look to hard at the code. But i did see atleast one divide by a variable. Is there any time this variable drops to 0? This would cause the crash.

No, the gluPerspective is called only once, before the loop. That can’t be the problem, cause at the start opengl does draw some frames. It crashes when the field first crosses the zNear plane of the viewing volume (picture the field coming closer to the camera). If I set the zNear bigger the program crashes quicker. If I set zNear to something positive near 0, it crashes when you are about to ‘step onto the field’.

Mm, I just compiled lesson 7 from NeHes tutorials in BCB5 and run. Guess what, now I get the same error when I zoom in ‘through’ the box. Seems my code is correct after all. Is this some bug in BCB5 or some opengl version, I cant find anything on the web about this.

what sort of hardware are you using. I seem to remember a similar problem cropping up with some older video cards which weren’t programmed to ignore certain divide by zero errors

I got a Voodoo3, and I should have the latest driver. BTW: when I run the precompiled version of lesson 7 it works just fine. I guess that means my voodoo is not the cause. Maybe I should check out the BCB forums.

Borland doesn’t turn off floating point exceptions by default which leads to the error you’re seeing. If you search these forums for “borland floating point exception” you’ll find info on how to fix it.

Yes, thats it. I got the FPU exceptions turned off now and it runs smoothly now.
Thank you guys!

oh, by the way, the command that I used is:

_control87(MCW_EM, MCW_EM);

with an #include <float.h>