Skip to content

Commit 91cecd2

Browse files
werner291v4hn
andauthored
Fixed possible nullpointer segfault (#95)
* Fixed possible nullpointer segfault Fix for #94 * safeguard more uses The last one forces a valid RobotState through the method API, so we can get the RobotModel from there without loading anything else. Co-authored-by: v4hn <[email protected]>
1 parent fa54dda commit 91cecd2

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/moveit_visual_tools.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,9 @@ bool MoveItVisualTools::publishContactPoints(const collision_detection::Collisio
11451145
bool MoveItVisualTools::publishTrajectoryPoint(const trajectory_msgs::JointTrajectoryPoint& trajectory_pt,
11461146
const std::string& planning_group, double display_time)
11471147
{
1148+
// Ensure robot_model_ is available
1149+
loadSharedRobotState();
1150+
11481151
// Get joint state group
11491152
const moveit::core::JointModelGroup* jmg = robot_model_->getJointModelGroup(planning_group);
11501153

@@ -1171,6 +1174,9 @@ bool MoveItVisualTools::publishTrajectoryPoint(const trajectory_msgs::JointTraje
11711174
bool MoveItVisualTools::publishTrajectoryPath(const std::vector<moveit::core::RobotStatePtr>& trajectory,
11721175
const moveit::core::JointModelGroup* jmg, double speed, bool blocking)
11731176
{
1177+
// Ensure robot_model_ is available
1178+
loadSharedRobotState();
1179+
11741180
// Copy the vector of RobotStates to a RobotTrajectory
11751181
robot_trajectory::RobotTrajectoryPtr robot_trajectory(
11761182
new robot_trajectory::RobotTrajectory(robot_model_, jmg->getName()));
@@ -1249,6 +1255,9 @@ bool MoveItVisualTools::publishTrajectoryPath(const moveit_msgs::RobotTrajectory
12491255
return false;
12501256
}
12511257

1258+
// Ensure that the robot name is available.
1259+
loadSharedRobotState();
1260+
12521261
// Create the message
12531262
moveit_msgs::DisplayTrajectory display_trajectory_msg;
12541263
display_trajectory_msg.model_id = robot_model_->getName();
@@ -1546,7 +1555,7 @@ bool MoveItVisualTools::hideRobot()
15461555

15471556
void MoveItVisualTools::showJointLimits(const moveit::core::RobotStatePtr& robot_state)
15481557
{
1549-
const std::vector<const moveit::core::JointModel*>& joints = robot_model_->getActiveJointModels();
1558+
const std::vector<const moveit::core::JointModel*>& joints = robot_state->getRobotModel()->getActiveJointModels();
15501559

15511560
// Loop through joints
15521561
for (std::size_t i = 0; i < joints.size(); ++i)

0 commit comments

Comments
 (0)