diff --git a/3rdparty/csv.hpp b/3rdparty/csv.hpp index 650ae199..51bb2600 100644 --- a/3rdparty/csv.hpp +++ b/3rdparty/csv.hpp @@ -36,11 +36,13 @@ SOFTWARE. #include #include +#include #include #include #include #include #include +#include #include #include #include @@ -6413,12 +6415,22 @@ namespace csv { /** @name Multi-Threaded File Reading: Flags and State */ ///@{ std::thread read_csv_worker; /**< Worker thread for read_csv() */ + // HDMapping: an exception escaping the worker thread called std::terminate; it is kept here instead and + // rethrown on the reading thread once the worker has been joined + std::exception_ptr read_csv_exception = nullptr; ///@} + /** Rethrow what read_csv() threw on the worker thread; call after joining it */ + void rethrow_read_csv_exception() { + if (this->read_csv_exception) + std::rethrow_exception(std::exchange(this->read_csv_exception, nullptr)); + } + /** Read initial chunk to get metadata */ void initial_read() { this->read_csv_worker = std::thread(&CSVReader::read_csv, this, internals::ITERATION_CHUNK_SIZE); this->read_csv_worker.join(); + this->rethrow_read_csv_exception(); } void trim_header(); @@ -7130,7 +7142,8 @@ namespace csv { std::error_code error; this->data_ptr->_data = std::make_shared>(mio::make_mmap_source(this->_filename, this->mmap_pos, length, error)); this->mmap_pos += length; - if (error) throw error; + // HDMapping: a std::exception naming the file instead of a bare std::error_code, which no caller catches + if (error) throw std::system_error(error, "cannot read '" + this->_filename + "'"); auto mmap_ptr = (mio::basic_mmap_source*)(this->data_ptr->_data.get()); @@ -7517,11 +7530,16 @@ namespace csv { // Tell read_row() to listen for CSV rows this->records->notify_all(); - this->parser->set_output(*this->records); - this->parser->next(bytes); + try { + this->parser->set_output(*this->records); + this->parser->next(bytes); - if (!this->header_trimmed) { - this->trim_header(); + if (!this->header_trimmed) { + this->trim_header(); + } + } + catch (...) { + this->read_csv_exception = std::current_exception(); // HDMapping: rethrown by the reading thread } // Tell read_row() to stop waiting @@ -7557,6 +7575,7 @@ namespace csv { // Reading thread is not active => start another one if (this->read_csv_worker.joinable()) this->read_csv_worker.join(); + this->rethrow_read_csv_exception(); // HDMapping: a failed chunk would otherwise be read again forever this->read_csv_worker = std::thread(&CSVReader::read_csv, this, internals::ITERATION_CHUNK_SIZE); } @@ -7594,6 +7613,7 @@ namespace csv { if (this->records->empty()) { this->read_csv_worker = std::thread(&CSVReader::read_csv, this, internals::ITERATION_CHUNK_SIZE); this->read_csv_worker.join(); + this->rethrow_read_csv_exception(); // Still empty => return end iterator if (this->records->empty()) return this->end(); diff --git a/AGENTS.md b/AGENTS.md index 357223aa..bf31dd15 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -121,7 +121,7 @@ Nothing fails if you miss one of these steps: 1. `add_subdirectory(apps/)` in the top-level `CMakeLists.txt`, under the right `BUILD_WITH_*` option. Without it the tool isn't built. 2. `hdmapping_install_app()` in the tool's `CMakeLists.txt`. Without it the tool is missing from the install - and the Debian package. + and the Debian package, and on Windows it lacks the UTF-8 manifest (`cmake/utf8.manifest`) and fails on non-ASCII paths. 3. The `EXPECTED` list in `deploy_mandeye.bat`. Without it the Windows deploy doesn't warn when the tool stops being built. diff --git a/apps/lidar_odometry_step_1/CMakeLists.txt b/apps/lidar_odometry_step_1/CMakeLists.txt index 15054aa5..fc550b33 100644 --- a/apps/lidar_odometry_step_1/CMakeLists.txt +++ b/apps/lidar_odometry_step_1/CMakeLists.txt @@ -23,6 +23,7 @@ set(SOURCES lidar_odometry.cpp lidar_odometry.h points_global_spill.h points_global_spill.cpp raw_cloud_loader.h raw_cloud_loader.cpp + output_folders.h output_folders.cpp toml_io.h toml_io.cpp ) diff --git a/apps/lidar_odometry_step_1/lidar_odometry.cpp b/apps/lidar_odometry_step_1/lidar_odometry.cpp index 855e7a21..7c6bf1ec 100644 --- a/apps/lidar_odometry_step_1/lidar_odometry.cpp +++ b/apps/lidar_odometry_step_1/lidar_odometry.cpp @@ -34,6 +34,15 @@ static bool save_cache_data(LidarOdometryParams& params, const std::string& path return true; } +//! Prints why compute_step_1 stopped and records it in the run report, whose errors the GUI shows. Returns false. +static bool step_1_failed(const LidarOdometryParams& params, const std::string& reason) +{ + std::cerr << reason << std::endl; + if (params.run_report) + params.run_report->fail(reason); + return false; +} + static void release_freed_heap() { #if defined(__GLIBC__) @@ -433,8 +442,10 @@ bool load_data( fs::path wdp = fs::path(working_directory) / "preview"; params.working_directory_preview = wdp.string(); - fs::path wdp_cache = fs::path(working_directory) / "cache"; - params.working_directory_cache = wdp_cache.string(); + const CacheLocation cache = current_cache_location(working_directory, params.session_cache_choice); + params.working_directory_cache = new_run_cache_folder(cache, working_directory).string(); + if (params.run_report && cache.kind != CacheKind::DataFolder) + params.run_report->addVolume(cache.base, "cache"); params.raw_cloud_loader.reset(); if (params.lazy_load_raw_clouds) @@ -471,10 +482,11 @@ bool load_data( minSize, [&](size_t i) { + auto data = L.load(i); + // after the read: a cloud drive may report other metadata once it has downloaded the file std::error_code ec; L.file_size[i] = fs::file_size(L.files[i], ec); L.file_time[i] = fs::last_write_time(L.files[i], ec); - auto data = L.load(i); L.n[i] = data.size(); if (!data.empty()) { @@ -741,10 +753,7 @@ bool compute_step_1( if (loader) { if (ppf.size() != loader->n.size()) - { - std::cerr << "lazy_load_raw_clouds: the cloud vector does not belong to the last load_data\n"; - return false; - } + return step_1_failed(params, "lazy_load_raw_clouds: the cloud vector does not belong to the last load_data"); // the flags describe THIS vector: a re-run reads every file again, and a file counts as loaded only if it is for (size_t i = 0; i < ppf.size(); i++) { @@ -755,7 +764,7 @@ bool compute_step_1( for (size_t fi = 0; fi < pointsPerFile.size(); fi++) { if (!lazy_ensure(loader, ppf, fi)) - return false; + return step_1_failed(params, loader->error); const auto& pp = pointsPerFile[fi]; // number_of_points += pp.size(); for (const auto& p : pp) @@ -797,10 +806,10 @@ bool compute_step_1( std::cout << "number of poses: " << poses.size() << std::endl; if (poses.empty()) - { - std::cerr << "Loading poses went wrong! Could not load poses!" << std::endl; - return false; - } + return step_1_failed( + params, + "No trajectory poses after the initial points: the IMU data is missing or ends before the LiDAR data (" + + std::to_string(trajectory.size()) + " IMU poses in total)"); int threshold = params.threshold_nr_poses; @@ -813,7 +822,7 @@ bool compute_step_1( if (!fs::exists(wdp_cache)) { std::cout << "Creating folder: " << wdp_cache << "\n"; - fs::create_directory(wdp_cache); + fs::create_directories(wdp_cache); // with a cache location that does not exist yet } for (size_t i = 0; i < n_iter; i++) @@ -860,7 +869,7 @@ bool compute_step_1( else if (L.t_first[index] < t1) // may hold points in [t0, t1): load; the search below decides { if (!lazy_ensure(loader, ppf, index)) - return false; + return step_1_failed(params, loader->error); } } } @@ -1480,6 +1489,7 @@ void remove_cache(const LidarOdometryParams& params) std::vector run_lidar_odometry(const std::string& input_dir, LidarOdometryParams& params) { HDMAP_ZONE_SCOPE("run_lidar_odometry"); + check_output_folders(input_dir, params.session_cache_choice); // before anything is loaded Session session; std::vector worker_data; std::vector input_file_names; diff --git a/apps/lidar_odometry_step_1/lidar_odometry_gui.cpp b/apps/lidar_odometry_step_1/lidar_odometry_gui.cpp index fc369fc0..3e54b3ec 100644 --- a/apps/lidar_odometry_step_1/lidar_odometry_gui.cpp +++ b/apps/lidar_odometry_step_1/lidar_odometry_gui.cpp @@ -702,6 +702,7 @@ void step1(const std::string& input_folder_name, const std::atomic& loPaus if (fs::exists(input_folder_name)) { + check_output_folders(input_folder_name, params.session_cache_choice); // before anything is loaded RunReport::Scope discovery(params.run_report.get(), RunReport::Stage::Loading); for (const auto& entry : fs::directory_iterator(input_folder_name)) if (entry.is_regular_file()) @@ -724,11 +725,13 @@ void step1(const std::string& input_folder_name, const std::atomic& loPaus else { std::string message_info = "Problem with loading data from folder '" + input_folder_name + - "' (Pease check if folder exists). Program will close once You click OK!!!"; + "' (Please check if folder exists). Program will close once You click OK!!!"; std::cout << message_info << std::endl; throw std::runtime_error("Input data loading failed: " + input_folder_name); } } + else + throw std::runtime_error("Data folder not found: " + input_folder_name); } void step2(const std::atomic& loPause) @@ -1989,6 +1992,8 @@ static void launchPipeline(const std::string& folder, bool compute, bool save) } } catch (const std::exception& error) { + // Loading a folder starts a new run report, so its errors are this run's reasons for the failure. + const auto reasons = params.run_report && !folder.empty() ? params.run_report->errors() : std::vector{}; if (params.run_report) { params.run_report->fail(error.what()); @@ -1996,10 +2001,13 @@ static void launchPipeline(const std::string& folder, bool compute, bool save) } std::lock_guard lock(completionMutex); completionMessage = std::string("Operation failed: ") + error.what(); + for (const auto& reason : reasons) + completionMessage += "\n" + reason; try { const fs::path input = folder.empty() ? fs::path(working_directory) : fs::path(folder); - if (fs::is_directory(input)) + // a folder that is not writable gets no failure report: the popup is the report + if (!dynamic_cast(&error) && fs::is_directory(input)) { const auto output = get_next_result_path(input.string()); if (save_failed_run_report(params, output, error.what())) @@ -2027,6 +2035,7 @@ bool step1( const std::atomic& loPause) { params.run_report = std::make_shared(folder, params.points_global_spill_directory, "cli"); + check_output_folders(folder, params.session_cache_choice); // before anything is loaded std::vector input_file_names; RunReport::Scope discovery(params.run_report.get(), RunReport::Stage::Loading); @@ -2083,6 +2092,49 @@ bool confirm_close() return false; } +//! Menu bar entry next to "Load & process scanning": shows where the cache goes and picks another location for this +//! session. The menu bar is hidden during a run, so the location cannot change under one. +static void cache_location_menu() +{ + const CacheLocation location = current_cache_location({}, params.session_cache_choice); + const char* kind = location.kind == CacheKind::DataFolder ? "data folder" + : location.kind == CacheKind::SystemTemp ? "system temp" + : "custom"; + const std::string title = std::string("Cache: ") + kind + "###cache_location"; + if (ImGui::BeginMenu(title.c_str())) + { + ImGui::TextDisabled("Where step 1 keeps its intermediate files (%s)", cache_source_label(location.source)); + if (location.kind == CacheKind::DataFolder) + ImGui::TextUnformatted("Next to the data: /cache_