Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Patch to fix loading images of the same name
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  15 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Nathan  
View profile  
 More options Oct 4 2012, 12:58 am
From: Nathan <nathan.sto...@gmail.com>
Date: Wed, 3 Oct 2012 22:58:40 -0600
Local: Thurs, Oct 4 2012 12:58 am
Subject: Patch to fix loading images of the same name

Currently, if you set pyglet.resource.path to ["foo"] and load "abc.png"
(foo/abc.png), and then change pyglet.resource.path to ["bar"] and try to
load "abc.png", you still get foo/abc.png, since the caching looks at the
name of the image file only.

This simple patch makes it so that the images are cached per specific
setting of pyglet.resource.path.  I included the patch as an attachment and
inline below since it's so tiny.

# HG changeset patch
# User Nathan Stocks <nathan.sto...@gmail.com>
# Date 1349326606 21600
# Node ID f8102f9ee5b19c43c6129dac070bf393f82e3ef7
# Parent  bf7f6c05275664ed76aab926944fe3a6a74ff022
Made it so that once you load an image, you can still load more images of
the same name by changing pyglet.resource.path.

diff -r bf7f6c052756 -r f8102f9ee5b1 pyglet/resource.py
--- a/pyglet/resource.py Sat Sep 15 16:48:08 2012 -0500
+++ b/pyglet/resource.py Wed Oct 03 22:56:46 2012 -0600
@@ -504,9 +504,9 @@
         '''
         self._require_index()
         if name in self._cached_images:
-            identity = self._cached_images[name]
+            identity = self._cached_images[str(self.path)+name]
         else:
-            identity = self._cached_images[name] = self._alloc_image(name,
+            identity = self._cached_images[str(self.path)+name] =
self._alloc_image(name,
                 atlas=atlas)

         if not rotate and not flip_x and not flip_y:

Works great for me!

Thoughts?

~ Nathan

  resource_cache_fix.diff
1K Download

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andre D  
View profile  
 More options Oct 4 2012, 7:35 am
From: Andre D <an...@andred.ca>
Date: Thu, 4 Oct 2012 07:35:40 -0400
Local: Thurs, Oct 4 2012 7:35 am
Subject: Re: Patch to fix loading images of the same name
Please use os.path.join to combine paths


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nathan  
View profile  
 More options Oct 4 2012, 11:36 am
From: Nathan <nathan.sto...@gmail.com>
Date: Thu, 4 Oct 2012 09:36:10 -0600
Local: Thurs, Oct 4 2012 11:36 am
Subject: Re: Patch to fix loading images of the same name

Andre, I'm not combining paths.  I'm using the string representation of the
current state of the list of paths to add a unique prefix to the key used
to cache the image.

For example, if pyglet.resource.path is ['my_sad_theme', 'my_happy_theme'],

...then the key will end up being the string  "['my_sad_theme',
'my_happy_theme']imagename"

If you change the path in any way, then the string representation of the
entire path list changes, which results in a different unique key, and a
new image searched for and cached using the new string representation of
the list as a prefix to the key.

Not quite as elegant as making a hash of the path state and using that as a
shorter prefix, but it definitely works.

~ Nathan


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nathan  
View profile  
 More options Oct 8 2012, 11:03 pm
From: Nathan <nathan.sto...@gmail.com>
Date: Mon, 8 Oct 2012 21:03:22 -0600
Local: Mon, Oct 8 2012 11:03 pm
Subject: Re: Patch to fix loading images of the same name

Sooo, would anyone be willing to commit this?  Or...?

~ Nathan


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Adam Bark  
View profile  
 More options Oct 9 2012, 5:00 am
From: Adam Bark <adam.jt...@gmail.com>
Date: Tue, 9 Oct 2012 10:00:05 +0100
Local: Tues, Oct 9 2012 5:00 am
Subject: Re: Patch to fix loading images of the same name

I should have some time to check it over tonight. Is there an issue for
this in the tracker?
On Oct 9, 2012 4:03 AM, "Nathan" <nathan.sto...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andreas Schiefer  
View profile  
 More options Oct 9 2012, 6:13 am
From: Andreas Schiefer <andreas.schie...@gmail.com>
Date: Tue, 9 Oct 2012 12:13:36 +0200
Local: Tues, Oct 9 2012 6:13 am
Subject: Re: Patch to fix loading images of the same name
I just noticed a small bug in this patch that causes it to never
actually use the cached images. The condition for testing if a cached
version is available still looks for "name" in the dict.

So the line
    if name in self._cached_images:
should of course read
    if str(self.path)+name in self._cached_images:

With that change, it might be desirable to put the value of
"str(self.path)+name" into a variable before the "if", instead of
computing it twice (for checking and then getting/setting the cached
image).

Additionally, for consistency reasons, I think we should add similar
changes to the texture() and animation() functions too, which also use
a cache.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nathan  
View profile  
 More options Oct 9 2012, 10:54 am
From: Nathan <nathan.sto...@gmail.com>
Date: Tue, 9 Oct 2012 08:54:54 -0600
Local: Tues, Oct 9 2012 10:54 am
Subject: Re: Patch to fix loading images of the same name

I will check.  Would you like me to create one if I don't find one?

~ Nathan


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nathan  
View profile  
 More options Oct 9 2012, 10:55 am
From: Nathan <nathan.sto...@gmail.com>
Date: Tue, 9 Oct 2012 08:55:44 -0600
Local: Tues, Oct 9 2012 10:55 am
Subject: Re: Patch to fix loading images of the same name

Good catch, and good ideas.

On Tue, Oct 9, 2012 at 4:13 AM, Andreas Schiefer <andreas.schie...@gmail.com


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Adam Bark  
View profile  
 More options Oct 9 2012, 3:03 pm
From: Adam Bark <adam.jt...@gmail.com>
Date: Tue, 9 Oct 2012 20:03:21 +0100
Local: Tues, Oct 9 2012 3:03 pm
Subject: Re: Patch to fix loading images of the same name

It might be good to document it if you can be bothered.
On Oct 9, 2012 3:54 PM, "Nathan" <nathan.sto...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nathan  
View profile  
 More options Oct 10 2012, 12:42 am
From: Nathan <nathan.sto...@gmail.com>
Date: Tue, 9 Oct 2012 22:42:10 -0600
Local: Wed, Oct 10 2012 12:42 am
Subject: Re: Patch to fix loading images of the same name

Absolutely.  I reviewed all open issues, and found no existing relevant
ones, so I added this as issue 612.

https://code.google.com/p/pyglet/issues/detail?id=612

~ Nathan


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Adam Bark  
View profile  
 More options Oct 10 2012, 6:09 pm
From: Adam Bark <adam.jt...@gmail.com>
Date: Wed, 10 Oct 2012 23:09:23 +0100
Local: Wed, Oct 10 2012 6:09 pm
Subject: Re: Patch to fix loading images of the same name

On 10/10/12 05:42, Nathan wrote:

> Absolutely.  I reviewed all open issues, and found no existing
> relevant ones, so I added this as issue 612.

> https://code.google.com/p/pyglet/issues/detail?id=612

> ~ Nathan

> On Tue, Oct 9, 2012 at 1:03 PM, Adam Bark <adam.jt...@gmail.com
> <mailto:adam.jt...@gmail.com>> wrote:

>     It might be good to document it if you can be bothered.

Thanks. I've posted a couple of things including a work around that I
would like opinions on.
Cheers,
Adam.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nathan  
View profile  
 More options Dec 3 2012, 1:05 am
From: Nathan <nathan.sto...@gmail.com>
Date: Sun, 2 Dec 2012 23:05:47 -0700
Local: Mon, Dec 3 2012 1:05 am
Subject: Re: Patch to fix loading images of the same name

Richard, while you're in a committing mood, can you commit Adam's patch for
issue 612?

https://code.google.com/p/pyglet/issues/detail?id=612#c2

I tested it, and it works great for me.  It's also a much more elegant (and
functional) solution than my quick-n-dirty attempt.

~ Nathan


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Adam Bark  
View profile  
 More options Dec 3 2012, 3:00 am
From: Adam Bark <adam.jt...@gmail.com>
Date: Mon, 03 Dec 2012 08:00:57 +0000
Local: Mon, Dec 3 2012 3:00 am
Subject: Re: Patch to fix loading images of the same name
On 03/12/12 06:05, Nathan wrote:
> Richard, while you're in a committing mood, can you commit Adam's
> patch for issue 612?

> https://code.google.com/p/pyglet/issues/detail?id=612#c2

> I tested it, and it works great for me.  It's also a much more elegant
> (and functional) solution than my quick-n-dirty attempt.

> ~ Nathan

I can commit it later, I was just waiting for confirmation that it works.
Thanks,
Adam.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nathan  
View profile  
 More options Dec 3 2012, 12:50 pm
From: Nathan <nathan.sto...@gmail.com>
Date: Mon, 3 Dec 2012 10:50:18 -0700
Local: Mon, Dec 3 2012 12:50 pm
Subject: Re: Patch to fix loading images of the same name

Oh, great.  Didn't realize you were a committer.

~ Nathan


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Adam Bark  
View profile  
 More options Dec 4 2012, 3:52 pm
From: Adam Bark <adam.jt...@gmail.com>
Date: Tue, 04 Dec 2012 20:52:30 +0000
Local: Tues, Dec 4 2012 3:52 pm
Subject: Re: Patch to fix loading images of the same name

On 03/12/12 17:50, Nathan wrote:

Ok issue 612 is now fixed as of changeset 9e151b2a47e4.
Adam.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »