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()