Skip to content

DefaultTextureAtlas crashes when textures are given to init #2395

Description

@bunny-therapist

Bug Report

arcade.DefaultTextureAtlas.__init__ has an argument called textures. Using this argument leads to a crash:

AttributeError: 'DefaultTextureAtlas' object has no attribute '_finalizers_created'

The reason appears to be that the attribute _finalizers_created (and a few others) are only created after the calls to self.add in where they are already used.

System Info

Arcade 3.0.0.dev36

vendor: Intel
renderer: Intel(R) UHD Graphics
version: (3, 3)
python: 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)]
platform: win32
pyglet version: 2.1.dev5
PIL version: 10.2.0

(Though, it appears that the code has not changed since 3.0.0.dev36 so I think the bug is still present.)

Actual behavior:

Passing non-empty textures argument to arcade.DefaultTextureAtlas.__init__ leads to a crash:

AttributeError: 'DefaultTextureAtlas' object has no attribute '_finalizers_created'

Expected behavior:

No crash when textures are used. Textures get added to atlas.

Steps to reproduce/example code:

import arcade
import PIL

class IssueDemonstrationWindow(arcade.Window):
    def __init__(self, initial_textures: bool = True, *args, **kwargs):
        super().__init__(*args, **kwargs)
        texture = arcade.Texture(PIL.Image.new('RGBA', (100, 100), arcade.color.RED))
        if initial_textures:
            arcade.DefaultTextureAtlas(
                size=(100, 100),
                textures=[texture]
            )
        else:
            atlas = arcade.DefaultTextureAtlas(
                size=(100, 100),
            )
            atlas.add(texture)

window = IssueDemonstrationWindow()  # crashes
# window = IssueDemonstrationWindow(initial_textures=False)  # does not crash
arcade.run()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions