From bb31e6b6b15ded0ae63065ab15c7d7d215a7cb68 Mon Sep 17 00:00:00 2001 From: Vantha Date: Wed, 31 Dec 2025 17:32:34 +0100 Subject: [PATCH] Prevent invalid GetEntityState GuiInterface calls As long as there's no entity under the cursor, 11 calls were made per tick with an undefined entity ID, which are now caught. In general, an "entity state" can very well be null if the passed ID is undefined, invalid or no entity with the ID exists (anymore). This last case is only noticed by the GuiInterface and currently used to detect destroyed entities. --- binaries/data/mods/public/gui/session/session.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/binaries/data/mods/public/gui/session/session.js b/binaries/data/mods/public/gui/session/session.js index 90f564cefb..4b50ded935 100644 --- a/binaries/data/mods/public/gui/session/session.js +++ b/binaries/data/mods/public/gui/session/session.js @@ -197,8 +197,15 @@ function GetMultipleEntityStates(ents) return entityStates; } +/** + * Get the current state of a given entity. The data is pulled from the simulation. + * The state is null, if the ID is undefined, invalid or no entity with the ID exists (anymore). + */ function GetEntityState(entId) { + if (!entId || entId == INVALID_ENTITY) + return null; + if (!g_EntityStates[entId]) { const entityState = Engine.GuiInterfaceCall("GetEntityState", entId);