fix: 安全关闭 MuJoCo 显示窗口

This commit is contained in:
2026-08-04 13:46:31 +08:00
parent 002484b610
commit 0dfe3d77dc
2 changed files with 36 additions and 0 deletions
@@ -4,6 +4,7 @@ from __future__ import annotations
import math
from pathlib import Path
import time
from typing import Callable
import mujoco
@@ -179,6 +180,8 @@ class DualArmSimulator(Node):
def close_viewer(self) -> None:
if self._viewer is not None:
self._viewer.close()
# MuJoCo 在后台 daemon 线程释放 GLX;立即退出解释器会触发段错误。
time.sleep(0.1)
self._viewer = None
@@ -188,6 +191,8 @@ def main(args=None) -> None:
try:
node = DualArmSimulator()
rclpy.spin(node)
except KeyboardInterrupt:
pass
finally:
if node is not None:
node.close_viewer()