如何修复Ign Gazebo的Ogre::InvalidParametersException异常
问题:Ignition Fortress加载带Visual的URDF时崩溃
环境
- Ubuntu 22.04
- ROS2 Humble
- Ignition Fortress
触发命令
执行以下命令加载URDF模型时程序崩溃:
ign service -s /world/empty/create --reqtype ignition.msgs.EntityFactory --reptype ignition.msgs.Boolean --timeout 1000 --req 'sdf_filename: "/ros_ws/src/mobot_description/urdf/mobot.urdf", name: "mobot_description"'
错误日志
➜ /ros_ws ign gazebo empty.sdf QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root' libEGL warning: MESA-LOADER: failed to open vgem: /usr/lib/dri/vgem_dri.so: cannot open shared object file: No such file or directory (search paths /usr/lib/x86_64-linux-gnu/dri:\$${ORIGIN}/dri:/usr/lib/dri, suffix _dri) libEGL warning: NEEDS EXTENSION: falling back to kms_swrast terminate called after throwing an instance of 'Ogre::InvalidParametersException' what(): OGRE EXCEPTION(2:InvalidParametersException): StagingBuffer cannot map 0 bytes in StagingBuffer::mapChecks at /build/ogre-next-UFfg83/ogre-next-2.2.5+dfsg3/OgreMain/src/Vao/OgreStagingBuffer.cpp (line 64) Stack trace (most recent call last) in thread 230276: #10 Object "[0xffffffffffffffff]", at 0xffffffffffffffff, in #9 Object "/lib/x86_64-linux-gnu/libc.so.6", at 0x7f708b5f584f, in #8 Object "/lib/x86_64-linux-gnu/libc.so.6", at 0x7f708b563ac2, in #7 Object "/lib/x86_64-linux-gnu/libQt5Core.so.5", at 0x7f7085c7e99d, in #6 Object "/lib/x86_64-linux-gnu/libQt5Core.so.5", at 0x7f7085c7cf90, in qTerminate() #5 Object "/lib/x86_64-linux-gnu/libstdc++.so.6", at 0x7f7087aff276, in std::terminate() #4 Object "/lib/x86_64-linux-gnu/libstdc++.so.6", at 0x7f7087aff20b, in #3 Object "/lib/x86_64-linux-gnu/libstdc++.so.6", at 0x7f7087af3b9d, in #2 Object "/lib/x86_64-linux-gnu/libc.so.6", at 0x7f708b4f77f2, in abort #1 Object "/lib/x86_64-linux-gnu/libc.so.6", at 0x7f708b511475, in raise #0 Object "/lib/x86_64-linux-gnu/libc.so.6", at 0x7f708b5659fc, in pthread_kill Aborted (Signal sent by tkill() 230206 0)
涉及的URDF内容
<?xml version="1.0" ?> <!-- =================================================================================== --> <!-- | This document was autogenerated by xacro from mobot_overall.urdf.xacro | --> <!-- | EDITING THIS FILE BY HAND IS NOT RECOMMENDED | --> <!-- =================================================================================== --> <robot name="mobot_description"> <link name="base_link"> <inertial> <origin rpy="0 0 0" xyz="0.0105481626504806 0.000121730205140724 -0.0536615390649162"/> <mass value="11.9970840115073"/> <inertia ixx="0.0265731409814962" ixy="1.52214545840681E-05" ixz="-0.000581289129660373" iyy="0.0533099030677871" iyz="-5.74575531055247E-07" izz="0.0503147943878383"/> </inertial> <!-- <visual> <origin rpy="0 0 0" xyz="0 0 0"/> <geometry> <mesh filename="/ros_ws/src/mobot_description/meshes/base_link.STL"/> </geometry> <material name=""> <color rgba="1 1 1 1"/> </material> </visual> --> <collision> <origin rpy="0 0 0" xyz="0 0 0"/> <geometry> <mesh filename="/ros_ws/src/mobot_description/meshes/base_link.STL"/> </geometry> </collision> </link> </robot>
已知情况
- 确认mesh文件路径正确,RViz2中可正常显示模型
- 删除URDF中的Visual部分后,Ignition不再崩溃,但需要保留Visual部分
解决方法
1. 修复STL文件格式问题
Ignition的Ogre渲染器对STL文件格式要求比RViz更严格,可能存在面数据异常:
- 用MeshLab打开
base_link.STL,执行Filters -> Cleaning and Repairing -> Remove Duplicate Vertices修复非流形结构 - 重新导出为二进制STL格式(避免ASCII格式的潜在兼容性问题)
2. 明确指定Visual部分的材质
原URDF中Visual的material name=""为空,可能导致渲染器初始化失败:
修改Visual的material节点,比如使用内置材质:
<visual> <origin rpy="0 0 0" xyz="0 0 0"/> <geometry> <mesh filename="/ros_ws/src/mobot_description/meshes/base_link.STL"/> </geometry> <material name="Gazebo/White"/> </visual>
或者自定义材质:
<visual> <origin rpy="0 0 0" xyz="0 0 0"/> <geometry> <mesh filename="/ros_ws/src/mobot_description/meshes/base_link.STL"/> </geometry> <material name="white_material"> <color rgba="1 1 1 1"/> </material> </visual>
3. 设置正确的环境变量
错误日志中提示XDG_RUNTIME_DIR未设置,先配置该变量再启动Ignition:
export XDG_RUNTIME_DIR=/tmp/runtime-$USER mkdir -p $XDG_RUNTIME_DIR chmod 0700 $XDG_RUNTIME_DIR ign gazebo empty.sdf
4. 更新Ignition依赖包
尝试升级Ignition Fortress相关组件,修复已知的渲染bug:
sudo apt update && sudo apt upgrade ignition-fortress
5. 转换URDF为SDF后加载
URDF转SDF后再加载,规避直接解析URDF的兼容性问题:
# 转换URDF到SDF gz sdf -p /ros_ws/src/mobot_description/urdf/mobot.urdf > /ros_ws/src/mobot_description/urdf/mobot.sdf # 加载SDF模型 ign service -s /world/empty/create --reqtype ignition.msgs.EntityFactory --reptype ignition.msgs.Boolean --timeout 1000 --req 'sdf_filename: "/ros_ws/src/mobot_description/urdf/mobot.sdf", name: "mobot_description"'
内容的提问来源于stack exchange,提问作者BugFree
相关产品推荐
相关产品推荐

