From 705dbec09a732f0a21ee66c04720ec19b086d940 Mon Sep 17 00:00:00 2001 From: Twist Date: Mon, 6 Jan 2025 19:51:25 +0000 Subject: [PATCH] Markervision fix: Fixed registry table being able to have duplicates (#1712) I discovered that when new marker vision objects are made with `markerVision.Add`, it doesn't clear out existing versions of the same object (matching ent and indentifier). This leads to the `markerVision.registry` table being filled up with objects that do not clear themselves, and makes `markerVision.Get` potentially return obsolete markers (mainly observed serverside). This PR resolves this possible bloat issue in the registry. This also fixes an issue where marker vision objects can incorrectly change to being visible to team or visible to role (clientside), when it's supposed to be visible to everyone. --- CHANGELOG.md | 1 + lua/ttt2/libraries/marker_vision.lua | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a7c20d6e..1b9723b7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,7 @@ All notable changes to TTT2 will be documented here. Inspired by [keep a changel - Fixed corpse searching sound playing when searched by a spectator, searched covertly, or searched long range (by @TW1STaL1CKY) - Fixed the mute button in the scoreboard not working (by @TW1STaL1CKY) - Fixed a few errors in shop error messages (by @Histalek) +- Fixed `markerVision`'s registry table being able to contain duplicate obsolete entries, thus fixing potential syncing issues with markers (by @TW1STaL1CKY) ### Changed diff --git a/lua/ttt2/libraries/marker_vision.lua b/lua/ttt2/libraries/marker_vision.lua index 43a2d6f6b..246d24340 100644 --- a/lua/ttt2/libraries/marker_vision.lua +++ b/lua/ttt2/libraries/marker_vision.lua @@ -31,6 +31,12 @@ markerVision.focussedMarkers = {} -- @return MARKER_VISION_ELEMENT The marker vision object that was created -- @realm shared function markerVision.Add(ent, identifier) + local _, index = markerVision.Get(ent, identifier) + + if index ~= -1 then + table.remove(markerVision.registry, index) + end + local mvObject = table.Copy(MARKER_VISION_ELEMENT) mvObject:SetEnt(ent) mvObject:SetIdentifier(identifier)