From fa6e9387cb9801081f378a4b4e978028ea531bd8 Mon Sep 17 00:00:00 2001 From: Einar Forselv Date: Sun, 28 Jul 2024 14:07:33 +0200 Subject: [PATCH] Atlas: Add more info when atlas is full (#2322) * Atlas: Add more info when atlas is full * Safely iterate unique textures --- arcade/texture_atlas/atlas_default.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/arcade/texture_atlas/atlas_default.py b/arcade/texture_atlas/atlas_default.py index a82170247..18c79ead2 100644 --- a/arcade/texture_atlas/atlas_default.py +++ b/arcade/texture_atlas/atlas_default.py @@ -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 @@ -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()