On Nov 11, 2007 1:41 PM, Ghislain Leveque <[EMAIL PROTECTED]> wrote: > Today I've come into a strange behavior with my rendering loop. > > I've measured the time to each call to this draw function and the > "normal" time is 15ms (quite fast) but from time to time, the function > takes 500ms to execute !! And of course I see my game freezing... > Are you 100% sure the problem is the rendering loop, and that it's not something else causing the problem?
The reason I ask is you said your draw function usually takes 15ms... if your target fps is 60, then that means drawing is taking more than 90% of your 16.6ms per frame budget. If there was some other external element causing a delay by interrupting your program, it would interrupt your draw 90% of the time, and would make it look like it was the draw's fault. One way to test this is to time all the parts of your game and log them or draw them to a real time display or something. If you see the 500ms delay come in some other component, or you see your game freeze but draw didn't go to 500ms, then you know that you are getting a long delay that draw is not causing. if that's the case, it's probably another app (this can happen with an app that takes 100% cpu, which it sounds like yours does if draw takes 15ms) or some background thread or asynchronous process (I think streaming audio with pygame can do it, or garbage collection like claxo suggested). You can sometimes discover the offender with either a live file access monitoring tool (try filemon if on windows) or by a live cpu use monitor (just see if some other process jumps in every few seconds) If you are 100% sure it's in your draw... then you could maybe try putting in code to time each draw, and do something special if it goes long. You could try doing the draw again and time that to find out if it's due to what & how you drew that particular frame or not. If a slow draw is repeatable, then you could run with a debugger and step through the bad draw. If it's not repeatable... well.. good luck to you...
