google-code-export / pyglet

Automatically exported from code.google.com/p/pyglet
BSD 3-Clause "New" or "Revised" License
1 stars 1 forks source link

It is currently not possible to load two sounds via pyglet.resource.media() that have the same name, but are in different directories. #612

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a hello world app that tries to load and play two different sounds 
via pyglet.resource.media, but whose files are the same name but in different 
directories.
2. No matter what you do to manipulate the path, whichever sound file you load 
first will be loaded second as well, because media is cached by name only.

What is the expected output?

I expect to be able to change the path, and then have it re-load files from 
different locations.

It becomes a very big issue when you make a themeable app, and want the same 
media file names for every bit of the theme, only stored in different 
directories.

Incomplete patch attached (updated patch to come).

Original issue reported on code.google.com by nathan.s...@gmail.com on 10 Oct 2012 at 4:41

Attachments:

GoogleCodeExporter commented 9 years ago
I can confirm the bug but your patch is for pyglet.resource.image and doesn't 
work.

Should we clear the cache on a reindex?

Original comment by Adam.JT...@gmail.com on 10 Oct 2012 at 9:43

GoogleCodeExporter commented 9 years ago
I tried resetting the cache when reindexing (reindexing should be done on path 
changes anyway) and it fixes the problem. If no one updates their path 
regularly then I think this fix is fine.

diff -r bf7f6c052756 pyglet/resource.py
--- a/pyglet/resource.py    Sat Sep 15 16:48:08 2012 -0500
+++ b/pyglet/resource.py    Wed Oct 10 22:47:13 2012 +0100
@@ -308,6 +308,9 @@
         You must call this method if `path` is changed or the filesystem
         layout changes.
         '''
+        self._cached_textures = weakref.WeakValueDictionary()
+        self._cached_images = weakref.WeakValueDictionary()
+        self._cached_animations = weakref.WeakValueDictionary()
         self._index = {}
         for path in self.path:
             if path.startswith('@'):

Original comment by Adam.JT...@gmail.com on 10 Oct 2012 at 9:55

GoogleCodeExporter commented 9 years ago
Nathan confirmed my fix and it is applied in changeset 9e151b2a47e4.

Original comment by Adam.JT...@gmail.com on 4 Dec 2012 at 12:40