Skip to content

Commit

Permalink
Atlas: Add more info when atlas is full (#2322)
Browse files Browse the repository at this point in the history
* Atlas: Add more info when atlas is full

* Safely iterate unique textures
  • Loading branch information
einarf committed Jul 28, 2024
1 parent 5d502a8 commit fa6e938
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions arcade/texture_atlas/atlas_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,19 @@ def unique_textures(self) -> list[Texture]:
"""
# Grab the first texture from each set
textures: list[Texture] = []
for tex_set in self._unique_textures.values():
# NOTE: keys can drop out of the dict during iteration.
# Copy they keys and look up each set to avoid this.
for key in list(self._unique_textures.keys()):
tex_set = self._unique_textures.get(key, None)
# Entry was GCed during iteration
if tex_set is None:
continue
# Corrupt data
if len(tex_set) == 0:
raise RuntimeError("Empty set in unique textures")

textures.append(next(iter(tex_set)))

return textures

@property
Expand Down Expand Up @@ -300,7 +309,12 @@ def _add(self, texture: Texture, create_finalizer=True) -> tuple[int, AtlasRegio
self.write_image(texture.image_data.image, x, y)
except AllocatorException:
if not self._auto_resize:
raise
raise AllocatorException(
f"No more space for image {texture.image_data.hash} "
f"size={texture.image.size}. "
f"Curr size: {self._size}. "
f"Max size: {self._max_size}"
)

# If we have lost regions/images we can try to rebuild the atlas
removed_image_count = self._image_ref_count.get_total_decref()
Expand Down

0 comments on commit fa6e938

Please sign in to comment.