fix: 安全关闭 MuJoCo 显示窗口
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user