[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] New on the mailing list with a strange FPS behavior



Hi!

    This seems to sound like either an anti-virus program running in the background or something like SKYPE that takes up CPU time and will lock up the computer at an unpredictable time. I think all other programs running in the background should be turned off...

        Bruce

----- Original Message ----- 
From: "claxo" <clazzt@xxxxxxxxxxxx>
To: <pygame-users@xxxxxxxx>
Sent: Sunday, November 11, 2007 9:33 PM
Subject: Re: [pygame] New on the mailing list with a strange FPS behavior




On 11 Nov 2007 at 22:41, Ghislain Leveque wrote:

> Hi there,
> 
> I subscribed to the mailing list today because I've used pygame for a
> while now and I begin to be comfortable with it.

Wellcome!

> Today I've come into a strange behavior with my rendering loop.
> 
> I use dirty rectangles to update the screen so my render function
> looks like this :
> 
> def draw(self):
>     self.spritegroup1.clear(self.window,self.background)
>     self.spritegroup2.clear(self.window,self.background)
>     # ...
> 
>     dirty = self.spritegroup1.draw(self.window) +
> self.spritegroup2.draw(self.window) # ...
>     pygame.display.update(dirty)
>     self.clock.tick (TARGET_FPS)
> 
> 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...
> 
> Can anyone tell me where I should look at ?
> -- 
> Ghislain Lévêque


1. I don't known if clock.tick() can be to blame, maybe you can try 
to bypass clock.tick to see if times are irregular.

2. If the size or quantity of sprites have great variations, so can 
the time. And if the workload is too variable, probably clock.tick 
can magnify the diference.

3. Memory garbage collection kicks in. you can try to do a explicit 
garbage collection after each M frames to see if max time is reduced.

4. At each frame you can try to print some stats to see if there 
something unexpected, by example:

print len(dirty), <other info that you think is relevant, maybe the 
total dirty area >

claxo