Visitar URL original
Only call remove_sprite on physics engines that have it by pvcraven · Pull Request #2952 · pythonarcade/arcade · GitHub
Skip to content

Only call remove_sprite on physics engines that have it - #2952

Merged
pvcraven merged 1 commit into
developmentfrom
fix/remove-sprite-from-any-engine
Oct 8, 2026
Merged

pvcraven merged 1 commit into
developmentfrom
fix/remove-sprite-from-any-engine

Conversation

@pvcraven

@pvcraven pvcraven commented Oct 8, 2026

Copy link
Copy Markdown
Member

Summary

Sprite.remove_from_sprite_lists() raised AttributeError for a sprite registered with a physics engine that has no remove_sprite() method. Found while triaging issues; there was no issue for it.

Cause: remove_from_sprite_lists() calls remove_sprite(self) on every engine in sprite.physics_engines.

  • PymunkPhysicsEngine registers itself, and is the only engine with remove_sprite().
  • register_physics_engine()'s docstring says any engine can be registered, for a sprite that needs a reference to its engine.

Doing that with PhysicsEngineSimple or PhysicsEnginePlatformer and then removing the sprite gave:

AttributeError: 'PhysicsEnginePlatformer' object has no attribute 'remove_sprite'

The sprite had already been removed from its sprite lists by then, so the call failed partway through.

Fix: it now only calls remove_sprite() on engines that have it. The simple and platformer engines only reference sprites through sprite lists, which remove_from_sprite_lists() already handles. The registered engines are still cleared afterwards.

Tests

New in tests/unit/sprite/test_sprite.py:

  • Registered simple or platformer engine: the sprite is removed from its list and the engines are cleared. Both cases fail on development.
  • An engine with remove_sprite(): it's still called. pymunk isn't installed here, so this uses a stand-in engine.

Full suite: 1802 passed. ruff, mypy and pyright all pass.

The changelog has an entry under Unreleased → Fixes.

🤖 Generated with Claude Code

Sprite.remove_from_sprite_lists() called remove_sprite() on every
engine registered with register_physics_engine(), but only
PymunkPhysicsEngine has that method. A sprite registered with
PhysicsEngineSimple or PhysicsEnginePlatformer raised AttributeError
after it had already been removed from its sprite lists. Engines
without remove_sprite() only reference sprites through sprite lists,
which are already handled, so they're skipped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pvcraven
pvcraven force-pushed the fix/remove-sprite-from-any-engine branch from d316caf to 2ce99d7 Compare October 8, 2026 18:50
@pvcraven
pvcraven merged commit 4f2018c into development Oct 8, 2026
7 checks passed
@pvcraven
pvcraven deleted the fix/remove-sprite-from-any-engine branch October 8, 2026 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant