Skip to content

Commit

Permalink
Fix crash on row change (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
smith-doug authored Feb 23, 2024
1 parent 7a2171b commit c17bd1a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 16 deletions.
9 changes: 9 additions & 0 deletions joint_trajectory/src/models/joint_trajectory_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,25 @@ bool JointTrajectoryModel::hasJointTrajectorySet(const boost::uuids::uuid& uuid)

JointTrajectoryStateItem* findJointStateItem(QStandardItem* item)
{
if (!item)
throw std::runtime_error("findJointStateItem: Invalid item selected");

if (item->type() == static_cast<int>(StandardItemType::JOINT_TRAJECTORY_SET_STATE))
return dynamic_cast<JointTrajectoryStateItem*>(item);

if (!item->parent())
throw std::runtime_error("findJointStateItem: Item without a parent selected");

return findJointStateItem(item->parent());
}

tesseract_common::JointState JointTrajectoryModel::getJointState(const QModelIndex& row) const
{
QStandardItem* item = itemFromIndex(row);

if (!item)
throw std::runtime_error("getJointState: invalid item, cannot get joint state");

if (item->type() == static_cast<int>(StandardItemType::JOINT_TRAJECTORY_SET_TRAJECTORY))
throw std::runtime_error("Cannot get joint state from selected joint trajectory standard item");

Expand Down
41 changes: 25 additions & 16 deletions joint_trajectory/src/widgets/joint_trajectory_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,26 +337,35 @@ void JointTrajectoryWidget::onCurrentRowChanged(const QModelIndex& current, cons
}
default:
{
events::JointTrajectoryToolbarState event(data_->model->getComponentInfo());
event.save_enabled = false;
event.remove_enabled = false;
event.plot_enabled = false;
QApplication::sendEvent(qApp, &event);
try
{
events::JointTrajectoryToolbarState event(data_->model->getComponentInfo());
event.save_enabled = false;
event.remove_enabled = false;
event.plot_enabled = false;
QApplication::sendEvent(qApp, &event);

const tesseract_common::JointState& state = data_->model->getJointState(current_index);
auto jts = data_->model->getJointTrajectorySet(current_index);
const tesseract_common::JointState& state = data_->model->getJointState(current_index);
auto jts = data_->model->getJointTrajectorySet(current_index);

if (jts.getEnvironment() != nullptr && jts.getEnvironment()->isInitialized())
{
if (data_->model->getComponentInfo()->hasParent() && data_->current_environment != jts.getEnvironment())
if (jts.getEnvironment() != nullptr && jts.getEnvironment()->isInitialized())
{
auto env_wrapper =
std::make_shared<DefaultEnvironmentWrapper>(data_->model->getComponentInfo(), jts.getEnvironment());
EnvironmentManager::set(env_wrapper);
if (data_->model->getComponentInfo()->hasParent() && data_->current_environment != jts.getEnvironment())
{
auto env_wrapper =
std::make_shared<DefaultEnvironmentWrapper>(data_->model->getComponentInfo(), jts.getEnvironment());
EnvironmentManager::set(env_wrapper);
}

data_->current_environment = jts.getEnvironment();
data_->current_environment->setState(state.joint_names, state.position);
}

data_->current_environment = jts.getEnvironment();
data_->current_environment->setState(state.joint_names, state.position);
}
catch (const std::runtime_error& ex)
{
std::stringstream sstr;
sstr << "Error in onCurrentRowChanged default, not updating env state: " << ex.what() << std::endl;
CONSOLE_BRIDGE_logDebug(sstr.str().c_str());
}

break;
Expand Down

0 comments on commit c17bd1a

Please sign in to comment.