Guard against calling null goal response callback (#738)

Also make sure to invoke the goal response callback before the result callback.

Signed-off-by: Jacob Perron <jacob@openrobotics.org>
This commit is contained in:
Jacob Perron 2019-05-23 21:00:58 -07:00 committed by GitHub
parent 29308dc8bc
commit 131a11bba5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -368,21 +368,23 @@ public:
// Do not use std::make_shared as friendship cannot be forwarded. // Do not use std::make_shared as friendship cannot be forwarded.
std::shared_ptr<GoalHandle> goal_handle( std::shared_ptr<GoalHandle> goal_handle(
new GoalHandle(goal_info, options.feedback_callback, options.result_callback)); new GoalHandle(goal_info, options.feedback_callback, options.result_callback));
{
std::lock_guard<std::mutex> guard(goal_handles_mutex_);
goal_handles_[goal_handle->get_goal_id()] = goal_handle;
}
promise->set_value(goal_handle);
if (options.goal_response_callback) {
options.goal_response_callback(future);
}
if (options.result_callback) { if (options.result_callback) {
try { try {
this->make_result_aware(goal_handle); this->make_result_aware(goal_handle);
} catch (...) { } catch (...) {
promise->set_exception(std::current_exception()); promise->set_exception(std::current_exception());
options.goal_response_callback(future);
return; return;
} }
} }
std::lock_guard<std::mutex> guard(goal_handles_mutex_);
goal_handles_[goal_handle->get_goal_id()] = goal_handle;
promise->set_value(goal_handle);
if (options.goal_response_callback) {
options.goal_response_callback(future);
}
}); });
return future; return future;
} }