From 5d3c631209ebe09fd952975f4a5a7550740a6635 Mon Sep 17 00:00:00 2001 From: Einar Forselv Date: Wed, 9 Oct 2024 00:53:28 +0200 Subject: [PATCH] DefaultTextureAtlas: Crash when supplying initial textures --- arcade/texture_atlas/atlas_default.py | 7 +++---- tests/unit/atlas/test_basics.py | 7 +++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/arcade/texture_atlas/atlas_default.py b/arcade/texture_atlas/atlas_default.py index 449e41887f..8ef1083e8b 100644 --- a/arcade/texture_atlas/atlas_default.py +++ b/arcade/texture_atlas/atlas_default.py @@ -171,14 +171,13 @@ def __init__( # atlas_name: Set of textures with matching atlas name self._unique_textures: dict[str, WeakSet[Texture]] = dict() - # Add all the textures - for tex in textures or []: - self.add(tex) - self._textures_added = 0 self._textures_removed = 0 self._finalizers_created = 0 + for tex in textures or []: + self.add(tex) + @property def max_width(self) -> int: """The maximum width of the atlas in pixels.""" diff --git a/tests/unit/atlas/test_basics.py b/tests/unit/atlas/test_basics.py index 2289e0fcbb..e7cdf371ef 100644 --- a/tests/unit/atlas/test_basics.py +++ b/tests/unit/atlas/test_basics.py @@ -22,6 +22,13 @@ def test_create(ctx, common): common.check_internals(atlas, images=0, textures=0, unique_textures=0) +def test_create_add(ctx, common): + """Create atlas with initial textures""" + texture = load_texture(":resources:onscreen_controls/shaded_dark/a.png") + atlas = DefaultTextureAtlas((100, 200), textures=[texture]) + common.check_internals(atlas, images=1, textures=1, unique_textures=1) + + def test_add(ctx, common): """Test adding textures to atlas""" tex_a = load_texture(":resources:onscreen_controls/shaded_dark/a.png")