los-cocos / cocos

graphic library for games and multimedia, for python language on PC-like hardware
http://los-cocos.github.io/cocos-site/
Other
633 stars 146 forks source link

Tile maps cause memory leaks #169

Closed ccanepa closed 10 years ago

ccanepa commented 10 years ago

From davexu...@gmail.com on October 02, 2011 12:53:52

What steps will reproduce the problem? 1. Run the code below (put the .py file in the test/ directory as it is based off of the test_tiles.py test)

  1. Open top or another process manager and watch as memory consumption goes up.

Here is the test:

# This code is so you can run the samples without installing the package
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))

import pyglet
from pyglet.window import key
from pyglet.gl import *

pyglet.resource.path.append(pyglet.resource.get_script_home())
pyglet.resource.reindex()

import cocos
from cocos import tiles, actions, layer, scenes

def make_scene():
    scroller = layer.ScrollingManager()
    test_layer = tiles.load('road-map.xml')['map0']
    scroller.add(test_layer)

    return cocos.scene.Scene(scroller)

if __name__ == "__main__":
    from cocos.director import director
    director.init(width=600, height=300, do_not_scale=True, resizable=True)

    def new_scene(dt):
        director.replace(cocos.scenes.transitions.FadeTransition(make_scene(), 1))
    pyglet.clock.schedule_interval(new_scene, 3)

    director.run(make_scene()) What is the expected output? What do you see instead? The output is correct but I expect the tile map data to be garbage collected but it doesn't seem to be happening. As far as I can tell, other layers that I have used do not have this issue. Memory output jumps up around 10MB for each scene change and the program quickly uses hundreds of MB of memory. What version of the product are you using? On what operating system? Tested on 0.4.0 and 0.5.0rc0

Original issue: http://code.google.com/p/los-cocos/issues/detail?id=169

ccanepa commented 10 years ago

From davexu...@gmail.com on October 02, 2011 08:54:36

Forgot to mention operating system. I am using Arch Linux.

ccanepa commented 10 years ago

From ccanepacc@gmail.com on October 02, 2011 21:30:14

Confirmed in windows xp sp3, python 2.6.6, cocos 0.5rc0, pyglet 1.2dev and pyglet 1.1.4 release. Eliminating the transition does not help. Need to investigate.

Status: Accepted
Labels: Type-Defect

ccanepa commented 10 years ago

From ccanepacc@gmail.com on October 29, 2011 10:09:37

Ok, the ultimate cause is that both ScrollingManager and ScrollableLayer are doing director.push_handlers(self.on_cocos_resize) in their on_enter method, but not a balancing pop in on_exit. That keeps references to the instances in director._event_stack even when the scene goes inactive.

If we add a pop at on_exit, the layers will miss notifications about window resize while they are inactive, so we need to ensure that at each on_enter we have code that handles resizes that happened when the nodes were not in the active scene.

I will look at the code and modify some test(s) in issue 153 (they exercise scrolling, both with and without tilemaps), then look for well behaved fixes.

Owner: ccanepacc@gmail.com

ccanepa commented 10 years ago

From ccanepacc@gmail.com on February 26, 2012 08:53:11

fixed at commit 53cebc1 attached specific test, fails with commit 322d9a7 , pass with commit 53cebc1

Status: TrunkFixed
Labels: OpSys-All Component-Tiles

ccanepa commented 10 years ago

From ccanepacc@gmail.com on August 13, 2012 17:52:19

fixed in cocos 0.5.5, closing

Status: Fixed

ccanepa commented 10 years ago

From dthomps...@worcester.edu on August 14, 2012 10:36:23

Thank you! :)