cartographer-project / cartographer

Cartographer is a system that provides real-time simultaneous localization and mapping (SLAM) in 2D and 3D across multiple platforms and sensor configurations.
Apache License 2.0
7.12k stars 2.25k forks source link

ordered_multi_queue.cc:45] Check failed: entry.second.finished #1840

Open JakeInit opened 3 years ago

JakeInit commented 3 years ago

When running cartographer, I can map and localize without any issues in my 2d environment. The issue happens when trying to delete my pointer to MapBuilderInterface.

std::unique_ptr mapbuilder; mapbuilder = std::make_unique(map_builderoptions); // options being my configurations from the lua

And for the trajectory builder cartographer::mapping::TrajectoryBuilderInterface *trajectory_builder; trajectory_id = mapbuilder->AddTrajectoryBuilder( {kRangeSensorId, kIMUSensorId, kOdomSensorId}, trajectory_builderoptions, GetLocalSlamResultCallback());

trajectory_builder = mapbuilder->GetTrajectoryBuilder(trajectory_id);

Everything during running is fine as stated above. Later when deconstructing my cartographerInterface class, I do the following:

// Finish trajectory
for (const auto &entry : map_builder_->pose_graph()->GetTrajectoryStates()) {
  if (entry.second == mapping::PoseGraph::TrajectoryState::ACTIVE) {
    auto trajectory_id = entry.first;
    map_builder_->FinishTrajectory(trajectory_id);
    while (!map_builder_->pose_graph()->IsTrajectoryFinished(trajectory_id)) {  // wait for each trajectory to finish
      std::this_thread::sleep_for(std::chrono::milliseconds(10));
    }
  }
}

// Run final optimizations
map_builder_->pose_graph()->RunFinalOptimization();
std::this_thread::sleep_for(std::chrono::milliseconds(150));

if(trajectory_builder != nullptr) {
  trajectory_builder = nullptr;
}

if(map_builder_ != nullptr) {
  map_builder_.reset();  // this is where the issue occurrs
}

As soon as I try to reset mapbuilder, I get the following log error and then crash of the application WARNING: Logging before InitGoogleLogging() is written to STDERR F0518 10:16:17.584446 15512 ordered_multi_queue.cc:45] Check failed: entry.second.finished Check failure stack trace: Aborted

This is called in the trajectory collator. I would have assumed since I called finish trajectory, that all trajecories (should only be 1) are labeled as finished. This seems to consistently happen if I stop sending sensor data to cartographer for a period of time and then start sending data again before trying to close my application.

Is there a way to handle this through the MapBuilderInterface and catch it to avoid crashing the application? Or am I missing a step when shutting down cartographer?

JakeInit commented 3 years ago

This seems to occur when trying to map an area, but sensor measurements are not pushed to Cartographer. Is there any way to prevent the crash in this scenario?

b-lala commented 2 years ago

I have the same problem, did you solve it?

VegetarianLion258 commented 1 year ago

maybe caused by building a new trajectory but the former trajectory not be destructed. only one trajectory is allowed.