Skip to content

Fix pybullet saveWorld resurrecting removed bodies after body ID reuse (#4810) - #4816

Open
paneendrakumar0 wants to merge 1 commit into
bulletphysics:masterfrom
paneendrakumar0:fix-pybullet-saveworld-removed-body-4810
Open

paneendrakumar0 wants to merge 1 commit into
bulletphysics:masterfrom
paneendrakumar0:fix-pybullet-saveworld-removed-body-4810

Conversation

@paneendrakumar0

@paneendrakumar0 paneendrakumar0 commented Oct 17, 2026 •

Copy link
Copy Markdown

Fixes #4810.

Description

In examples/SharedMemory/PhysicsServerCommandProcessor.cpp, PyBullet tracks loaded models in m_saveWorldBodyData. Previously, when a body was removed via processRemoveBodyCommand(), its body ID was freed in m_bodyHandles but was never removed from m_saveWorldBodyData.

When a subsequent body load operation allocated and reused that newly freed body ID, saveWorld() resolved the stale record through the newly created body handle and serialized both assets at the new body's transform, causing deleted bodies to be resurrected in saved Python worlds.

Solution

  • When a body is removed in PhysicsServerCommandProcessor::processRemoveBodyCommand(), locate and remove its bodyUniqueId from m_saveWorldBodyData.
  • If a SaveWorldObjectData entry has no remaining bodies, remove the entry from m_saveWorldBodyData.
  • Added regression unit test test_save_world_removed_body_reuse to TestPybulletMethods in examples/pybullet/unittests/unittests.py.

bulletphysics#4810)

When a body is removed via processRemoveBodyCommand, its body ID was
freed in m_bodyHandles but remained in m_saveWorldBodyData. If a later
body reused that body ID, saveWorld() resolved the stale record through
the new body and serialized both assets at the new body's transform.

This commit purges the removed bodyUniqueId from m_saveWorldBodyData
upon body removal, and deletes empty SaveWorldObjectData entries.
A regression unit test is added to TestPybulletMethods.
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.

PyBullet saveWorld resurrects a removed object after body-ID reuse

1 participant