naturerobots / mesh_tools

Tools and Messages for Annotated 3D Triangle Meshes in ROS
https://wiki.ros.org/mesh_tools
BSD 3-Clause "New" or "Revised" License
229 stars 42 forks source link

Fix segfault when using non-textured, but colored materials #15

Closed BuildingAtom closed 2 years ago

BuildingAtom commented 2 years ago

I added a check for has_texture from the MeshMaterial message so textureIndex would resolve false for enteringTexturedTriangleMesh to fix a segfault for non-textured, but colored materials. Otherwise, the textureIndex would be set to whatever value and Rviz would proceed to segfault since that textureIndex may not be a valid index (i.e. if there weren't any textures whatsoever). This was a problem with rospy since the automatic serialization would always associate a value to texture_index, and the boost::optional<uint32_t> would never evaluate false. I don't know if this occurs in roscpp as well.

Additionally I changed the cluster material association part of the material service request function so that each cluster would use the respective material from cluster_materials instead of the material with the identical index to the cluster. Since it also looked like a nearby line was not used for anything, I commented that out as well.

Since this was only a 3 line change, I combined it into one commit. Hopefully that isn't a problem!