Permalink
Browse files

reload: for texture / images, when we are reloading, prevent to use t…

…he Cache for storing the temporary image object, as well as the texture created from that Image object. closes #581
  • Loading branch information...
1 parent f9dfb39 commit a601a6b3c5508073832b8b2a3e0ac492011acc7b @tito tito committed Aug 1, 2012
Showing with 13 additions and 5 deletions.
  1. +7 −4 kivy/core/image/__init__.py
  2. +3 −0 kivy/graphics/context.pyx
  3. +2 −0 kivy/graphics/context_instructions.pyx
  4. +1 −1 kivy/graphics/texture.pyx
@@ -136,11 +136,12 @@ class ImageLoaderBase(object):
'''Base to implement an image loader.'''
__slots__ = ('_texture', '_data', 'filename', 'keep_data',
- '_mipmap')
+ '_mipmap', '_nocache')
def __init__(self, filename, **kwargs):
self._mipmap = kwargs.get('mipmap', False)
self.keep_data = kwargs.get('keep_data', False)
+ self._nocache = kwargs.get('nocache', False)
self.filename = filename
self._data = self.load(filename)
self._textures = None
@@ -166,7 +167,8 @@ def populate(self):
if texture is None:
texture = Texture.create_from_data(
self._data[count], mipmap=self._mipmap)
- Cache.append('kv.texture', uid, texture)
+ if not self._nocache:
+ Cache.append('kv.texture', uid, texture)
# set as our current texture
self._textures.append(texture)
@@ -363,7 +365,7 @@ class Image(EventDispatcher):
'''
copy_attributes = ('_size', '_filename', '_texture', '_image',
- '_mipmap')
+ '_mipmap', '_nocache')
def __init__(self, arg, **kwargs):
# this event should be fired on animation of sequenced img's
@@ -373,6 +375,7 @@ def __init__(self, arg, **kwargs):
self._mipmap = kwargs.get('mipmap', False)
self._keep_data = kwargs.get('keep_data', False)
+ self._nocache = kwargs.get('nocache', False)
self._size = [0, 0]
self._image = None
self._filename = None
@@ -578,7 +581,7 @@ def _set_filename(self, value):
tmpfilename = self._filename
image = ImageLoader.load(
self._filename, keep_data=self._keep_data,
- mipmap=self._mipmap)
+ mipmap=self._mipmap, nocache=self._nocache)
self._filename = tmpfilename
# put the image into the cache if needed
@@ -122,6 +122,7 @@ cdef class Context:
cdef Shader shader
cdef Canvas canvas
+ image_objects = Cache._objects['kv.image']
Cache.remove('kv.image')
Cache.remove('kv.shader')
@@ -171,6 +172,8 @@ cdef class Context:
# Restore texture cache
texture_objects.update(Cache._objects['kv.texture'])
Cache._objects['kv.texture'] = texture_objects
+ image_objects.update(Cache._objects['kv.image'])
+ Cache._objects['kv.image'] = image_objects
Logger.debug('Context: Reload vbos')
for item in self.l_vbo[:]:
@@ -267,6 +267,8 @@ cdef class BindTexture(ContextInstruction):
def __set__(self, object texture):
if not texture:
texture = get_default_texture()
+ Logger.trace('BindTexture: setting texture %r (previous is %r)' % (
+ texture, self._texture))
self._texture = texture
property index:
@@ -758,7 +758,7 @@ cdef class Texture:
self._id = texture.id
else:
from kivy.core.image import Image
- image = Image(self._source)
+ image = Image(self._source, nocache=True)
self._id = image.texture.id
texture = image.texture
texture._nofree = 1

0 comments on commit a601a6b

Please sign in to comment.