mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-03-28 09:33:52 +00:00
fix: guard texture log dedup sets with mutex for thread safety
loadTexture() is called from terrain worker threads, but the static unordered_set dedup caches for missing-texture and decode-failure warnings had no synchronization. Add std::mutex guards around both log-dedup blocks to prevent data races.
This commit is contained in:
parent
fb3bfe42c9
commit
b5b84fbc19
1 changed files with 5 additions and 0 deletions
|
|
@ -6,6 +6,7 @@
|
|||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <limits>
|
||||
#include <mutex>
|
||||
#include <unordered_set>
|
||||
|
||||
#include "stb_image.h"
|
||||
|
|
@ -182,10 +183,12 @@ BLPImage AssetManager::loadTexture(const std::string& path) {
|
|||
|
||||
std::vector<uint8_t> blpData = readFile(normalizedPath);
|
||||
if (blpData.empty()) {
|
||||
static std::mutex logMtx;
|
||||
static std::unordered_set<std::string> loggedMissingTextures;
|
||||
static bool missingTextureLogSuppressed = false;
|
||||
static const size_t kMaxMissingTextureLogKeys =
|
||||
parseEnvCount("WOWEE_TEXTURE_MISS_LOG_KEYS", 400);
|
||||
std::lock_guard<std::mutex> lock(logMtx);
|
||||
if (loggedMissingTextures.size() < kMaxMissingTextureLogKeys &&
|
||||
loggedMissingTextures.insert(normalizedPath).second) {
|
||||
LOG_WARNING("Texture not found: ", normalizedPath);
|
||||
|
|
@ -199,10 +202,12 @@ BLPImage AssetManager::loadTexture(const std::string& path) {
|
|||
|
||||
BLPImage image = BLPLoader::load(blpData);
|
||||
if (!image.isValid()) {
|
||||
static std::mutex logMtx;
|
||||
static std::unordered_set<std::string> loggedDecodeFails;
|
||||
static bool decodeFailLogSuppressed = false;
|
||||
static const size_t kMaxDecodeFailLogKeys =
|
||||
parseEnvCount("WOWEE_TEXTURE_DECODE_LOG_KEYS", 200);
|
||||
std::lock_guard<std::mutex> lock(logMtx);
|
||||
if (loggedDecodeFails.size() < kMaxDecodeFailLogKeys &&
|
||||
loggedDecodeFails.insert(normalizedPath).second) {
|
||||
LOG_ERROR("Failed to load texture: ", normalizedPath);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue