Skip to content

Commit

Permalink
Fixing a race condition in the MultiRotor, where the reset function c…
Browse files Browse the repository at this point in the history
…an sometimes be skipped over. This can happen if the reset task is created in between the updateRenderedState and updateRendering function calls.
  • Loading branch information
tachitachi committed Feb 26, 2018
1 parent fcb01f5 commit 4144aba
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Unreal/Plugins/AirSim/Source/Multirotor/MultiRotorConnector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ MultiRotorConnector::MultiRotorConnector(VehiclePawnWrapper* vehicle_pawn_wrappe
last_pose_ = pending_pose_ = last_debug_pose_ = Pose::nanPose();
pending_pose_status_ = PendingPoseStatus::NonePending;
reset_pending_ = false;
did_reset_ = false;

std::string message;
if (!vehicle_.getController()->isAvailable(message)) {
Expand Down Expand Up @@ -146,6 +147,7 @@ void MultiRotorConnector::updateRenderedState(float dt)
//if reset is pending then do it first, no need to do other things until next tick
if (reset_pending_) {
reset_task_();
did_reset_ = true;
return;
}

Expand Down Expand Up @@ -200,8 +202,15 @@ void MultiRotorConnector::updateRendering(float dt)
{
//if we did reset then don't worry about synchrnozing states for this tick
if (reset_pending_) {
reset_pending_ = false;
return;
// Continue to wait for reset
if (!did_reset_) {
return;
}
else {
reset_pending_ = false;
did_reset_ = false;
return;
}
}

try {
Expand Down Expand Up @@ -363,6 +372,7 @@ void MultiRotorConnector::reset()
reset_task_ = std::packaged_task<void()>([this]() { resetPrivate(); });
std::future<void> reset_result = reset_task_.get_future();
reset_pending_ = true;
did_reset_ = false;
reset_result.wait();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class MultiRotorConnector : public msr::airlib::VehicleConnectorBase

//reset must happen while World is locked so its async task initiated from API thread
bool reset_pending_;
bool did_reset_;
std::packaged_task<void()> reset_task_;

Pose last_pose_; //for trace lines showing vehicle path
Expand Down

0 comments on commit 4144aba

Please sign in to comment.