mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-04-17 01:23:51 +00:00
fix: data race on collision query profiling counters
queryTimeMs and queryCallCount on WMORenderer and M2Renderer were plain mutable doubles/uint32s written by getFloorHeight (dispatched on async threads from CameraController) and read by the main thread. This is undefined behavior per C++ — thread sanitizer would flag it. Changed to std::atomic with relaxed ordering (adequate for diagnostics) and updated QueryTimer to use atomic fetch_add/compare_exchange.
This commit is contained in:
parent
3dd1128ecf
commit
bbb560f93c
3 changed files with 23 additions and 12 deletions
|
|
@ -5,6 +5,7 @@
|
|||
#include <vulkan/vulkan.h>
|
||||
#include <vk_mem_alloc.h>
|
||||
#include <glm/glm.hpp>
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
|
|
@ -531,9 +532,10 @@ private:
|
|||
std::unordered_map<uint32_t, size_t> instanceIndexById;
|
||||
// Collision scratch buffers are thread_local (see m2_renderer.cpp) for thread-safety.
|
||||
|
||||
// Collision query profiling (per frame).
|
||||
mutable double queryTimeMs = 0.0;
|
||||
mutable uint32_t queryCallCount = 0;
|
||||
// Collision query profiling — atomic because getFloorHeight is dispatched
|
||||
// on async threads from camera_controller while the main thread reads these.
|
||||
mutable std::atomic<double> queryTimeMs{0.0};
|
||||
mutable std::atomic<uint32_t> queryCallCount{0};
|
||||
|
||||
// Persistent render buffers (avoid per-frame allocation/deallocation)
|
||||
struct VisibleEntry {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue