C : printf changes course of program

435 views Asked by At

I've got a program that simulates collisions (circles) using openGL, GLUT, GLUI. Everything worked fine but when I changed my code a bit it began to do weird things.

I have 2 buttons, "play" and "step", "play" simulates the collisions updated with a timer, "step" also simulates but you've got to click it in order to go further.

Originally it did that but now the "play" button acts the same as "step". If I add a printf in my timer callback it all works perfectly...

What can I do ?

In my timer_cb I only have got :

 // printf("something\n");
 glutPostRedisplay();
 glutTimerFunc(getDeltaT(), timer_cb, 0);
1

There are 1 answers

0
Luca On

The I/O routines, like printf, introduce a sensible delay by calling them. To answer with a certain degree of correctness you show us the User Interface code, but I think I can guess...

Are you using threads? Maybe it can be a concurrency bug because the execution of the button event handler is not synchronized with the update logic?