Skip to content

Fix member destruction order in SimulationRunner#3460

Closed
taylorhoward92 wants to merge 2 commits intogazebosim:mainfrom
taylorhoward92:fix/simulationrunner-destruction-order
Closed

Fix member destruction order in SimulationRunner#3460
taylorhoward92 wants to merge 2 commits intogazebosim:mainfrom
taylorhoward92:fix/simulationrunner-destruction-order

Conversation

@taylorhoward92
Copy link
Copy Markdown
Contributor

@taylorhoward92 taylorhoward92 commented Apr 7, 2026

🦟 Bug fix

Summary

systemMgr was declared before eventMgr and entityCompMgr in SimulationRunner.hh. C++ destroys members in reverse declaration order, so systemMgr was being destroyed after those managers. However, systems hold references to both the EventManager and EntityComponentManager, so they must be stopped and destroyed first to avoid use-after-free on shutdown.

Changes

Move the systemMgr declaration after eventMgr and entityCompMgr so that it is destroyed first. The existing comments acknowledged this requirement ("must be before EntityComponentManager") but the declaration order was incorrect — "before" in the comment meant "destroyed before", but in C++ that requires declaring after.

Checklist

  • Signed all commits for DCO
  • Added a screen capture or video to the PR description that demonstrates the fix (as needed)
  • Added tests
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • Consider updating Python bindings (if the library has them)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • Updated Bazel files (if adding new files). Created an issue otherwise.
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers
  • Was GenAI used to generate this PR? If so, make sure to add "Generated-by" to your commits. (See this policy for more info.)

Generated-by: Claude Code

Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by and Generated-by messages.

@taylorhoward92 taylorhoward92 changed the base branch from main to gz-sim10 April 7, 2026 10:47
@taylorhoward92 taylorhoward92 changed the base branch from gz-sim10 to main April 7, 2026 10:50
@taylorhoward92 taylorhoward92 marked this pull request as ready for review April 7, 2026 11:07
@taylorhoward92 taylorhoward92 requested a review from arjo129 as a code owner April 7, 2026 11:07
@taylorhoward92 taylorhoward92 force-pushed the fix/simulationrunner-destruction-order branch 2 times, most recently from dcddb9a to 34eda28 Compare April 9, 2026 02:45
systemMgr must be destroyed before eventMgr and entityCompMgr because
systems hold references to both managers. Rather than reordering member
declarations (which changes class layout and breaks Windows CI), explicitly
reset systemMgr in the destructor. The destructor body runs before implicit
member destruction, so systems are cleanly stopped while both managers are
still alive.

Signed-off-by: Taylor Howard <taylorhoward@me.com>
Generated-by: Claude Code

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@taylorhoward92 taylorhoward92 force-pushed the fix/simulationrunner-destruction-order branch from 34eda28 to 66b8eab Compare April 9, 2026 03:14
@taylorhoward92
Copy link
Copy Markdown
Contributor Author

This change is causing issues on Windows and was just an additional safety net on top of the change in #3459. Closing for now.

@github-project-automation github-project-automation Bot moved this from Inbox to Done in Core development Apr 9, 2026
@arjo129
Copy link
Copy Markdown
Contributor

arjo129 commented Apr 10, 2026

Thanks for being a good citizen about this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants