Skip to content

Texture cache file entries allow duplicates because the cache key is a new Path instance each time #1752

Closed
@cspotcode

Description

@cspotcode

Bug Report

May be related to #1586. Uncovered by pyright.

TextureCache does this:

if self._strong_file_entries.get(file_path):
raise ValueError(f"File path {file_path} already in cache")
if file_path:
self._strong_file_entries.put(str(file_path), texture)

Except that file_path is an instance of Path. This means the if will always fail and that exception will never throw.

I think the tests are relying on this behavior since they load the same texture multiple times:

file = ":resources:images/space_shooter/playerShip1_orange.png"
# We don't cache hit boxes with no algo
texture = load_texture(file, hit_box_algorithm=hitbox.algo_bounding_box)
assert arcade.cache.hit_box_cache.get(texture.cache_name) is None
assert len(arcade.cache.hit_box_cache) == 0
# We cache hit boxes with an algo
texture_1 = load_texture(file, hit_box_algorithm=hitbox.algo_simple)
texture_2 = load_texture(file, hit_box_algorithm=hitbox.algo_detailed)
assert len(arcade.cache.texture_cache) == 3
assert len(arcade.cache.hit_box_cache) == 2

I can include a fix as part of my work on #1751, but I'm not sure what the fix should be: throw the exception? Silently allow the same entry to be put in cache multiple times?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions