From 4f4ce28f63f9c2a6b4f0153fe778ab2e4efbb727 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tur=C3=A1nszki=20J=C3=A1nos?= Date: Sat, 1 Feb 2025 07:17:54 +0100 Subject: [PATCH] simplify more --- WickedEngine/wiBacklog.cpp | 26 +++++++++++--------------- WickedEngine/wiVersion.cpp | 2 +- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/WickedEngine/wiBacklog.cpp b/WickedEngine/wiBacklog.cpp index 97acb86b3c..6cbf476678 100644 --- a/WickedEngine/wiBacklog.cpp +++ b/WickedEngine/wiBacklog.cpp @@ -54,8 +54,9 @@ namespace wi::backlog std::deque entries; std::mutex entriesLock; - std::string getTextWithoutLock() + std::string getText() { + std::scoped_lock lck(entriesLock); std::string retval; for (auto& x : entries) { @@ -63,24 +64,18 @@ namespace wi::backlog } return retval; } - void writeLogfileWithoutLock() + void writeLogfile() { static const std::string filename = wi::helper::GetCurrentPath() + "/log.txt"; - std::string text = getTextWithoutLock(); + std::string text = getText(); wi::helper::FileWrite(filename, (const uint8_t*)text.c_str(), text.length()); } - void writeLogfile() - { - std::scoped_lock lck(entriesLock); - writeLogfileWithoutLock(); - } ~InternalState() { // The object will automatically write out the backlog to the temp folder when it's destroyed // Should happen on application exit - std::scoped_lock lck(entriesLock); - writeLogfileWithoutLock(); + writeLogfile(); } } internal_state; @@ -303,7 +298,7 @@ namespace wi::backlog params.cursor = {}; if (refitscroll) { - float textheight = wi::font::TextHeight(getText(), params); // getText() locks! + float textheight = wi::font::TextHeight(getText(), params); float limit = canvas.GetLogicalHeight() - 50; if (scroll + textheight > limit) { @@ -319,9 +314,11 @@ namespace wi::backlog params.enableLinearOutputMapping(9); } - internal_state.entriesLock.lock(); static std::deque entriesCopy; - entriesCopy = internal_state.entries; // Force copy because drawing text while locking is not safe because on error it might try to lock again! + + internal_state.entriesLock.lock(); + // Force copy because drawing text while locking is not safe because an error inside might try to lock again! + entriesCopy = internal_state.entries; internal_state.entriesLock.unlock(); for (auto& x : entriesCopy) @@ -346,8 +343,7 @@ namespace wi::backlog std::string getText() { - std::scoped_lock lck(internal_state.entriesLock); - return internal_state.getTextWithoutLock(); + return internal_state.getText(); } void clear() { diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 78479ef865..8ec602c24c 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wi::version // minor features, major updates, breaking compatibility changes const int minor = 71; // minor bug fixes, alterations, refactors, updates - const int revision = 669; + const int revision = 670; const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);