Pygame memory leak with transform.flip -


Today I came across an interesting issue which, by writing a small side scroller, instead of a sprite sheet, I was planning to use because I lacked a good "packer" for making phantom sheets (and honestly with patience and passion as it is only a test project).

Anyway, I showed the animation running on the right of 8 PNG (with transparency). I considered it a good idea to prepare the flipped images to run on the left in the consultant, and the frame is not framed when the game is running (Flip actually consumes a lot of CPU like I Was measured).

> To get access to the loop, I get the memory leak

  self.move_l = [# 8 PNG images with transparency to the right] For the self in IMG. Move_l: self.move_r.append (pygame.transform.flip (img, true, false)  

error traceback:

  traceback (most recent Call final): The file "D: \ Python 34 \ _Projects \ efg \ efg.py", in line 196, in the & lt; module & gt; main = master program ((1024, 680)) "D: \ Python 34 \ _Projects \ efg \ efg.py ", line 31, __init__ in self player = actor. Player (screen_size) file" D: \ Python 34 \ _Projects \ efg \ actors.py ", in line 30, __init__ self. Move_r.append (pygame.transform.flip (Img, True, False)) pygame.error: Out of memory  

When I copy I connect each image separately, it works perfectly:

  self.mov E_r = [self] Move_r.append (pygame.transform.flip (self.move_l [0] , True, False)) self.move_r.append (pygame.transform.flip (self.move_l [1], true, wrong)) self.move_r.append (pygame.transform.flip (self.move_l [2], True, wrong)) self.move_r.append (pygame.transform.flip (self.move_l [3], true, wrong)) self.move_r.append (pygame.transform.flip (self.move_l [4], True , Fellus)) self.move_r.append (pygame.transform.flip (self.move_l [5], true, false)) self Move_r.append (pygame.transform.flip (self.move_l [6], correct, incorrect)) self.move_r.append (pygame.transform.flip (self.move_l [7], true, incorrect))  

Does anyone have a clue that makes a difference between using them one by one and loop? I also tried loop for a while:

  _index = 0 while Lennon (self.move_r)  

this has also worked No memory leak, I'm thinking what happens between the two solutions after the difference - one after the other to use the loop - for the loop (which I thought was faster than the loop of a time and Should be more efficient).

I appreciate any suggestion that the problem of my game has been solved (I either of the loop I can use or add one after another), but I am really curious about what can happen due to such behavior.

Thanks

Patrick

The problem is resolved! In the second part of the code (not shown here) Move_l was also added to the array, so the source array continues to grow, resulting in the result of the memory leak.

This For loop, while loop and separately add loop to everyone, according to my measurements are most efficient.


Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -