mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-20 16:14:58 +01:00
fix(physicslog): nothing that goes wrong in the writing ends the simulator; a name in 1250 makes a path on a Windows set to UTF-8
The writer's thread called flush() with nothing around it, so an exception leaving write() ended the process with std::terminate, with no message. One that happens: the file of a log was made a std::filesystem::path of the vehicle's name, which MSVC converts in the code page of the system and throws for bytes not of it; on a Windows with "Use Unicode UTF-8 for worldwide language support" a vehicle named in 1250, as the sceneries have them (0xB3 for ł), isn't UTF-8. - the file of a log is made of the name with MultiByteToWideChar without MB_ERR_INVALID_CHARS: the same file as before for every name of the code page, U+FFFD for the bytes not of it instead of a throw. Elsewhere the bytes are the name of the file as they were - a log whose writing throws for any other reason (memory) is kept for the next try as one whose file can't be written, and the other logs are written still - the thread, flush_for() and stop() write through flush_safely(), which lets nothing out: what was taken for a writing failing as a whole is lost and told in the log, the next writing goes on - the messages name the file by the bytes of the name, not by path::string(), which converts back Tests: a log which can't be written doesn't keep the others from theirs; a vehicle named in 1250 has its log, read back by physicslog_writer::file(). Reported in the review of #385. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -44,6 +44,9 @@ public:
|
||||
bool flush_for(std::chrono::milliseconds Timeout);
|
||||
// writes what is kept and ends the thread. what is given after is written by a flush, or at the end
|
||||
void stop();
|
||||
// the file of the log Name, made of its bytes as they are: those of the code page of a scenery (1250) too, on a
|
||||
// Windows set to UTF-8, where the standard library throws making a path of them. there they become U+FFFD
|
||||
std::filesystem::path file(std::string const &Name) const;
|
||||
|
||||
private:
|
||||
struct pending {
|
||||
@@ -55,10 +58,18 @@ private:
|
||||
// the thread, on the first line given, unless stopped. called with m_mutex held
|
||||
void start();
|
||||
void run(std::stop_token const &Stop);
|
||||
// as flush, letting nothing out: on the writer's thread, or at the end of the process, an exception would end the
|
||||
// simulator. what was taken for a writing which failed as a whole is lost, the next one goes on with what came since
|
||||
void flush_safely() noexcept;
|
||||
// called with m_filemutex held
|
||||
void write();
|
||||
// the lines of the log Name written into its file. returns: true if they all were
|
||||
bool write_log(std::string const &Name, pending const &Lines) const;
|
||||
// the file of the log Name, for the log of the simulator
|
||||
std::string shown(std::string const &Name) const;
|
||||
|
||||
std::filesystem::path const m_folder;
|
||||
std::string const m_shownfolder;
|
||||
std::chrono::milliseconds const m_interval;
|
||||
std::mutex m_mutex; // the lines kept and the thread
|
||||
std::map<std::string, pending> m_pending;
|
||||
|
||||
Reference in New Issue
Block a user