Skip to content

Commit fa6e938

Browse files
authored
Atlas: Add more info when atlas is full (#2322)
* Atlas: Add more info when atlas is full * Safely iterate unique textures
1 parent 5d502a8 commit fa6e938

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

arcade/texture_atlas/atlas_default.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,19 @@ def unique_textures(self) -> list[Texture]:
240240
"""
241241
# Grab the first texture from each set
242242
textures: list[Texture] = []
243-
for tex_set in self._unique_textures.values():
243+
# NOTE: keys can drop out of the dict during iteration.
244+
# Copy they keys and look up each set to avoid this.
245+
for key in list(self._unique_textures.keys()):
246+
tex_set = self._unique_textures.get(key, None)
247+
# Entry was GCed during iteration
248+
if tex_set is None:
249+
continue
250+
# Corrupt data
244251
if len(tex_set) == 0:
245252
raise RuntimeError("Empty set in unique textures")
253+
246254
textures.append(next(iter(tex_set)))
255+
247256
return textures
248257

249258
@property
@@ -300,7 +309,12 @@ def _add(self, texture: Texture, create_finalizer=True) -> tuple[int, AtlasRegio
300309
self.write_image(texture.image_data.image, x, y)
301310
except AllocatorException:
302311
if not self._auto_resize:
303-
raise
312+
raise AllocatorException(
313+
f"No more space for image {texture.image_data.hash} "
314+
f"size={texture.image.size}. "
315+
f"Curr size: {self._size}. "
316+
f"Max size: {self._max_size}"
317+
)
304318

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

0 commit comments

Comments
 (0)