From db42ccae717f175106491f7ff360ea6a0090d32b Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Sat, 25 May 2024 11:12:31 +1000 Subject: [PATCH] fix Assets filesByExtension storing duplicate asset paths slipped in with the asset load scripts - this caused rare duplication errors when the Databases parse assets by extension and an asset path is indexed with more than one capitalization #66 --- source/base/StarAssets.cpp | 14 +++++++------- source/base/StarAssets.hpp | 10 +++++----- source/core/StarString.hpp | 2 ++ 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/source/base/StarAssets.cpp b/source/base/StarAssets.cpp index 7475a04..1519e86 100644 --- a/source/base/StarAssets.cpp +++ b/source/base/StarAssets.cpp @@ -371,7 +371,7 @@ StringList Assets::scan(String const& suffix) const { StringList Assets::scan(String const& prefix, String const& suffix) const { StringList result; if (suffix.beginsWith(".") && !suffix.substr(1).hasChar('.')) { - StringSet filesWithExtension = scanExtension(suffix); + auto& filesWithExtension = scanExtension(suffix); for (auto const& file : filesWithExtension) { if (file.beginsWith(prefix, String::CaseInsensitive)) result.append(file); @@ -386,11 +386,11 @@ StringList Assets::scan(String const& prefix, String const& suffix) const { return result; } -const StringSet NullStringSet; +const CaseInsensitiveStringSet NullExtensionScan; -StringSet const& Assets::scanExtension(String const& extension) const { +CaseInsensitiveStringSet const& Assets::scanExtension(String const& extension) const { auto find = m_filesByExtension.find(extension.beginsWith(".") ? extension.substr(1) : extension); - return find != m_filesByExtension.end() ? find->second : NullStringSet; + return find != m_filesByExtension.end() ? find->second : NullExtensionScan; } Json Assets::json(String const& path) const { @@ -416,7 +416,7 @@ void Assets::queueJsons(StringList const& paths) const { })); } -void Assets::queueJsons(StringSet const& paths) const { +void Assets::queueJsons(CaseInsensitiveStringSet const& paths) const { MutexLocker assetsLocker(m_assetsMutex); for (String const& path : paths) { auto components = AssetPath::split(path); @@ -439,7 +439,7 @@ void Assets::queueImages(StringList const& paths) const { })); } -void Assets::queueImages(StringSet const& paths) const { +void Assets::queueImages(CaseInsensitiveStringSet const& paths) const { MutexLocker assetsLocker(m_assetsMutex); for (String const& path : paths) { auto components = AssetPath::split(path); @@ -482,7 +482,7 @@ void Assets::queueAudios(StringList const& paths) const { })); } -void Assets::queueAudios(StringSet const& paths) const { +void Assets::queueAudios(CaseInsensitiveStringSet const& paths) const { MutexLocker assetsLocker(m_assetsMutex); for (String const& path : paths) { auto components = AssetPath::split(path); diff --git a/source/base/StarAssets.hpp b/source/base/StarAssets.hpp index 54cbb2f..6b454e8 100644 --- a/source/base/StarAssets.hpp +++ b/source/base/StarAssets.hpp @@ -190,7 +190,7 @@ public: // Scans all assets for files with the given extension, which is specially // indexed and much faster than a normal scan. Extension may contain leading // '.' character or it may be omitted. - StringSet const& scanExtension(String const& extension) const; + CaseInsensitiveStringSet const& scanExtension(String const& extension) const; // Get json asset with an optional sub-path. The sub-path portion of the // path refers to a key in the top-level object, and may use dot notation @@ -204,7 +204,7 @@ public: // Load all the given jsons using background processing. void queueJsons(StringList const& paths) const; - void queueJsons(StringSet const& paths) const; + void queueJsons(CaseInsensitiveStringSet const& paths) const; // Returns *either* an image asset or a sub-frame. Frame files are JSON // descriptor files that reference a particular image and label separate @@ -216,7 +216,7 @@ public: ImageConstPtr image(AssetPath const& path) const; // Load images using background processing void queueImages(StringList const& paths) const; - void queueImages(StringSet const& paths) const; + void queueImages(CaseInsensitiveStringSet const& paths) const; // Return the given image *if* it is already loaded, otherwise queue it for // loading. ImageConstPtr tryImage(AssetPath const& path) const; @@ -231,7 +231,7 @@ public: AudioConstPtr audio(String const& path) const; // Load audios using background processing void queueAudios(StringList const& paths) const; - void queueAudios(StringSet const& paths) const; + void queueAudios(CaseInsensitiveStringSet const& paths) const; // Return the given audio *if* it is already loaded, otherwise queue it for // loading. AudioConstPtr tryAudio(String const& path) const; @@ -331,7 +331,7 @@ private: // Maps the source asset name to the source containing it CaseInsensitiveStringMap m_files; // Maps an extension to the files with that extension - CaseInsensitiveStringMap m_filesByExtension; + CaseInsensitiveStringMap m_filesByExtension; ByteArray m_digest; diff --git a/source/core/StarString.hpp b/source/core/StarString.hpp index 9c18515..2280fb6 100644 --- a/source/core/StarString.hpp +++ b/source/core/StarString.hpp @@ -359,6 +359,8 @@ struct CaseInsensitiveStringCompare { typedef HashSet StringSet; +typedef HashSet CaseInsensitiveStringSet; + template , typename ComparatorT = std::equal_to> using StringMap = HashMap;