Jump to content
  • Advertisement
Sign in to follow this  
Ruudje

OpenGL Engine crashing due to camera angle?

This topic is 4705 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
Here's the function that renders the default model


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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!