From 94b7c7f01b6c45512aa9b28ffa7bd889459f7488 Mon Sep 17 00:00:00 2001 From: maj00r Date: Mon, 16 Nov 2026 02:08:04 +0100 Subject: [PATCH] fix(physicslog): the writer's destructor throws nothing, its wait a plain condition variable woken to stop; a driver of no vehicle controls nothing --- utilities/physicslog.cpp | 11 +++++++++-- utilities/physicslog.h | 2 +- vehicle/Driver.cpp | 4 ++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/utilities/physicslog.cpp b/utilities/physicslog.cpp index 299b74221..19f18684b 100644 --- a/utilities/physicslog.cpp +++ b/utilities/physicslog.cpp @@ -40,7 +40,11 @@ void keep_last(std::string &Text, std::size_t const Most) { physicslog_writer::physicslog_writer(std::filesystem::path Folder, std::chrono::milliseconds const Interval) : m_folder{std::move(Folder)}, m_interval{Interval} {} physicslog_writer::~physicslog_writer() { - stop(); + // at the end of the process: what the logs couldn't keep, memory or a file, isn't to end it worse + try { + stop(); + } catch (...) { + } } void physicslog_writer::begin(std::string const &Name, std::string_view const Header) { @@ -94,6 +98,9 @@ void physicslog_writer::stop() { } if (thread.joinable()) { thread.request_stop(); + // the writer waits under the lock: taken once, it's either about to wait, seeing the stop, or waiting already + { std::scoped_lock lock{m_mutex}; } + m_wake.notify_all(); thread.join(); } flush(); @@ -111,7 +118,7 @@ void physicslog_writer::run(std::stop_token const &Stop) { { std::unique_lock lock{m_mutex}; // woken early only to stop, which writes the rest itself - if (m_wake.wait_for(lock, Stop, m_interval, [] { return false; }) || Stop.stop_requested()) + if (m_wake.wait_for(lock, m_interval, [&Stop] { return Stop.stop_requested(); })) return; } flush(); diff --git a/utilities/physicslog.h b/utilities/physicslog.h index 44d04b4c3..9ecb88349 100644 --- a/utilities/physicslog.h +++ b/utilities/physicslog.h @@ -63,7 +63,7 @@ private: std::mutex m_mutex; // the lines kept and the thread std::map m_pending; bool m_stopped{false}; - std::condition_variable_any m_wake; + std::condition_variable m_wake; std::jthread m_thread; std::thread::id m_writer; // of the thread, kept after it is taken to be joined: the writer knows itself by it std::mutex m_filemutex; // the files are written one batch at a time, so the lines of a log stay in order diff --git a/vehicle/Driver.cpp b/vehicle/Driver.cpp index 23d778bdb..d2ebd1fd7 100644 --- a/vehicle/Driver.cpp +++ b/vehicle/Driver.cpp @@ -6372,6 +6372,10 @@ void TController::ControllingSet() // problematyczne jest sterowanie z członu biernego, dlatego damy AI silnikowy // dzięki temu będzie wirtualna kabina w silnikowym, działająca w rozrządczym // w plikach FIZ zostały zgubione ujemne maski sprzęgów, stąd problemy z EZT + if( pVehicle == nullptr ) { + // a driver of no vehicle has nothing to control + return; + } mvOccupied = pVehicle->MoverParameters; // domyślny skrót do obiektu parametrów BrakeSystem = mvOccupied->BrakeSystem; // domyślny sposób hamowania mvControlling = pVehicle->FindPowered()->MoverParameters; // poszukiwanie członu sterowanego