Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions embodichain/lab/sim/sim_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ def __new__(cls, sim_config: SimulationManagerCfg = SimulationManagerCfg()):
instance = super(SimulationManager, cls).__new__(cls)
# Store sim_config in the instance for use in __init__ or elsewhere
instance.sim_config = sim_config
instance._is_constructed = False
cls._instances[n_instance] = instance
return instance

Expand Down Expand Up @@ -378,6 +379,8 @@ def __init__(
if sim_config.headless is False:
self._window = self._world.get_windows()

self._is_constructed = True

@classmethod
def get_instance(cls, instance_id: int = 0) -> SimulationManager:
"""Get the instance of SimulationManager by id.
Expand Down Expand Up @@ -3117,6 +3120,12 @@ def _deferred_destroy(self) -> None:
self.stop_window_record()
self.wait_window_record_saves()

# Stop the render loop before releasing scene resources. Vulkan window
# presentation may otherwise continue acquiring swapchain images while
# Env::Clean tears down render objects used by the in-flight frame.
if getattr(self, "is_window_opened", False):
self.close_window()

import sys, gc

self.clean_materials()
Expand Down
26 changes: 20 additions & 6 deletions scripts/tutorials/atomic_action/tutorial_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,16 +230,30 @@ def run_tutorial(main: Callable[[], None]) -> None:
Args:
main: Zero-argument tutorial entry point.
"""
interrupted = False
try:
main()
try:
main()
except KeyboardInterrupt:
# Handle Ctrl+C before native cleanup. An active traceback keeps
# main() locals (including borrowed C++ material wrappers) alive;
# destroying World first would make their later destructors unsafe.
interrupted = True
logger.log_info("Tutorial interrupted; shutting down cleanly.")
finally:
if SimulationManager.is_instantiated():
sim = SimulationManager.get_instance()
if sim.is_window_recording():
sim.stop_window_record()
sim.wait_window_record_saves()
sim.destroy(exit_process=False)
SimulationManager.flush_cleanup_queue()
if not getattr(sim, "_is_constructed", False):
SimulationManager.reset(getattr(sim, "instance_id", 0))
Comment on lines 243 to +247

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Regression tests absent from changeset

The new interrupt, partial-construction, and native teardown branches have no accompanying test changes, so later regressions in this lifecycle-sensitive behavior will not be detected by the repository's automated coverage despite the PR description claiming new regression tests.

Context Used: AGENTS.md (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: scripts/tutorials/atomic_action/tutorial_utils.py
Line: 243-247

Comment:
**Regression tests absent from changeset**

The new interrupt, partial-construction, and native teardown branches have no accompanying test changes, so later regressions in this lifecycle-sensitive behavior will not be detected by the repository's automated coverage despite the PR description claiming new regression tests.

**Context Used:** AGENTS.md ([source](https://github.com/dexforce/embodichain/blob/main/AGENTS.md))

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Codex Fix in Claude Code

else:
if sim.is_window_recording():
sim.stop_window_record()
sim.wait_window_record_saves()
sim.destroy(exit_process=False)
SimulationManager.flush_cleanup_queue()

if interrupted:
raise SystemExit(130)


def add_ur5_gripper_robot(
Expand Down
Loading