I don't really want to post my code as it's thousands of lines, very untidy and a mixture of C and assembly...
BUT... Here is the problem. I was trying to debug a collision detection algorithm so I was doing a lot of "printf" calls including the newline character "\n". I was probably printing about 100 newlines per second. My previously well-behaved opengl drawing went crazy. Objects moved about the screen in a really jittery/jerky way, for example something that was meant to move by one pixel would appear to move by 10 pixels. However, when I printed out the coordinates to the terminal during drawing (before and after a lot of matrix multiplication) it still showed a smooth one pixel increase.
I eventually narrowed the problem down to the newline "\n" character. Remove all newlines, and the opengl code would behave perfectly. Also, if I redirected the "\n" characters to a file on disk, the code would behave perfectly. From Googling I understand that printf is "flushed" every time a "\n" is encountered. Does this involve a switch from user mode to kernel mode, or any other long delay etc.? Something that would explain this behaviour? Or does it suggest some other bug in my code?
Thanks revolution I will try what you suggested. Problem is the program (as well as being large) has masses of dependencies and I can't really expect others to install it just to hunt for this bug. I just know that sometimes coders get intuition about things and can suggest a fix. For example I helped someone out a while back with a segfault and didn't need to read his code just his description of what he was trying to do.
Anyway, I've just ruled out the possibility that printf("\n") is causing timing problems. It takes up almost no time. Maybe if I can shave the code down to a few hundred lines I will post it on here, certainly not in a compilable state though. IIRC even the .tar.gz file is too big for this forum.
Okay I fixed the problem.
I had this call (probably copied and pasted from the web) in my C code:
I changed it to:
And now things are super smooth even when printing loads of newlines. It seems strange that newlines and the swap interval would interact in that way, but apparently they do. And yes I suppose, if all else fails, read the source.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum