Engine crashing due to camera angle?
Hi all,
I'm facing a strange problem I have been unable to figure out by myself...
I have restarted a basic opengl engine, with support for 3ds files and bmp textures so far. On to the problem:
I added some simple formulas to make the camera perform a certain fly-by of the default model. I used the sin and cos functions with timeGetTime, nothing special, but after a certain time (I THINK it's because of the angle of the camera) the screen freezes and goes black after which the system crashes. If it doesn't crash, the system resets the VPU (ATI Radeon 9700 Pro) so the screen goes black for 1 second, resumes the program only to still crash within the next minute.
I have tried 2 completely different models, both with the same resutls.
I have tried the program without the formulaes, i.e. a static camera, and then it works fine.
What could be causing this?
Check by outputting values after your sin / cos functions but before rendering where you are getting a divide-by-zero. I think it's a pretty safe bet that that is the problem here.
/edit: Darn, beaten! I opened this window and checked my e-mail before replying.
/edit: Darn, beaten! I opened this window and checked my e-mail before replying.
Here's the function that renders the default model
This is the code that doesn't crash. If I alter the GLU_Lookat to...
...things go wrong as described above.
void Update(void){ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); if(myApp->GetKey(VK_ESCAPE)) { myApp->Update_ptr = &Quit; return; } gluLookAt( 400.0f, 300.0f, 600.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f ); GLfloat LightPosition[]= { 1.0f, 0.6f, 0.7f, 0.0f }; glLightfv(GL_LIGHT0, GL_POSITION, LightPosition); glBegin(GL_TRIANGLES); obj_Default.Render_3ds(); glEnd();}
This is the code that doesn't crash. If I alter the GLU_Lookat to...
gluLookAt( sin(timeGetTime() / 1500.0f) * 1200, cos(timeGetTime() / 1400.0f) * 1200, 600.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f );
...things go wrong as described above.
My guess is that you're getting denormalized values. Try setting your fp precision to round to zero mode or clamp your input values for sin && cos to "reasonable" values.
cast the timegettime() function to a float: (float)timegettime()
because it returns a short integer.(I think dword is a short integer)
and change 1200 into 1200.0f
this are the two things where it could go wrong.
veel geluk
[Edited by - delta user on December 3, 2005 7:07:11 AM]
because it returns a short integer.(I think dword is a short integer)
and change 1200 into 1200.0f
this are the two things where it could go wrong.
veel geluk
[Edited by - delta user on December 3, 2005 7:07:11 AM]
Try to write your own code instead of gluLookAt. Then if there is division by 0 you'd get a runtime error, and maybe even a line number.
This is kinda weird, only tan usually causes problems, not sin and cos.
This is kinda weird, only tan usually causes problems, not sin and cos.
I tried your code in one of my apps and it works fine.
It is verry weird because your app doesn't crash immediatly.
if it would be the camera code it should crash when your camera code gets executed for the first time and that would be when you start your app.
sorry for the code above. it was bad code so i removed it.
It is verry weird because your app doesn't crash immediatly.
if it would be the camera code it should crash when your camera code gets executed for the first time and that would be when you start your app.
sorry for the code above. it was bad code so i removed it.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement