From 93cb764c23c693f68a0c6a83f5e39dc8469de0cb Mon Sep 17 00:00:00 2001 From: FutureRave Date: Wed, 19 Jan 2022 19:32:49 +0000 Subject: [PATCH] :lock: Used the wrong locks :lock: --- .../Modules/AssetInterfaces/IMaterial.cpp | 6 +++--- src/Components/Modules/ZoneBuilder.cpp | 2 +- src/Game/Functions.cpp | 20 ++++++++++--------- src/Game/Functions.hpp | 5 +++-- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/Components/Modules/AssetInterfaces/IMaterial.cpp b/src/Components/Modules/AssetInterfaces/IMaterial.cpp index 23f63ef2..637064b7 100644 --- a/src/Components/Modules/AssetInterfaces/IMaterial.cpp +++ b/src/Components/Modules/AssetInterfaces/IMaterial.cpp @@ -199,7 +199,7 @@ namespace Assets replacementFound = true; } } - }, false, false); + }, false); if (!replacementFound) { @@ -236,7 +236,7 @@ namespace Assets replacementFound = true; } } - }, false, false); + }, false); } if (!replacementFound && asset->techniqueSet) @@ -274,7 +274,7 @@ namespace Assets replacementFound = true; } } - }, false, false); + }, false); if (!replacementFound) { diff --git a/src/Components/Modules/ZoneBuilder.cpp b/src/Components/Modules/ZoneBuilder.cpp index a9a38a33..c48132f9 100644 --- a/src/Components/Modules/ZoneBuilder.cpp +++ b/src/Components/Modules/ZoneBuilder.cpp @@ -981,7 +981,7 @@ namespace Components replacementFound = true; } } - }, false, false); + }, false); if (replacementFound) return ret; return ""; diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index 6f949634..43a9fe55 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -504,12 +504,16 @@ namespace Game vec3_t* CorrectSolidDeltas = reinterpret_cast(0x739BB8); // Count 26 - void Sys_UnlockWrite(FastCriticalSection* critSect) + void Sys_LockRead(FastCriticalSection* critSect) { - assert(critSect->writeCount > 0); + InterlockedIncrement(&critSect->readCount); + while (critSect->writeCount) std::this_thread::sleep_for(1ms); + } - InterlockedDecrement(&critSect->writeCount); - Sys_TempPriorityEnd(&critSect->tempPriority); + void Sys_UnlockRead(FastCriticalSection* critSect) + { + assert(critSect->readCount > 0); + InterlockedDecrement(&critSect->readCount); } XAssetHeader ReallocateAssetPool(XAssetType type, unsigned int newSize) @@ -626,10 +630,9 @@ namespace Game return false; } - void DB_EnumXAssetEntries(XAssetType type, std::function callback, bool overrides, bool lock) + void DB_EnumXAssetEntries(XAssetType type, std::function callback, bool overrides) { - if (lock) - Sys_LockWrite(db_hashCritSect); + Sys_LockRead(db_hashCritSect); const auto pool = Components::Maps::GetAssetEntryPool(); for(auto hash = 0; hash < 37000; hash++) @@ -658,8 +661,7 @@ namespace Game } } - if(lock) - Sys_UnlockWrite(db_hashCritSect); + Sys_UnlockRead(db_hashCritSect); } // this cant be MessageBox because windows.h has a define that converts it to MessageBoxW. which is just stupid diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index 9d49115a..78281dab 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -1034,7 +1034,8 @@ namespace Game extern vec3_t* CorrectSolidDeltas; - void Sys_UnlockWrite(FastCriticalSection*); + void Sys_LockRead(FastCriticalSection* critSect); + void Sys_UnlockRead(FastCriticalSection* critSect); XAssetHeader ReallocateAssetPool(XAssetType type, unsigned int newSize); void Menu_FreeItemMemory(Game::itemDef_s* item); @@ -1049,7 +1050,7 @@ namespace Game XAssetType DB_GetXAssetNameType(const char* name); int DB_GetZoneIndex(const std::string& name); bool DB_IsZoneLoaded(const char* zone); - void DB_EnumXAssetEntries(XAssetType type, std::function callback, bool overrides, bool lock); + void DB_EnumXAssetEntries(XAssetType type, std::function callback, bool overrides); XAssetHeader DB_FindXAssetDefaultHeaderInternal(XAssetType type); XAssetEntry* DB_FindXAssetEntry(XAssetType type, const char* name);