Skip to content

Commit

Permalink
fix(core): fixed Lua error caused by empty guid for some units
Browse files Browse the repository at this point in the history
  • Loading branch information
casualshammy committed Nov 3, 2024
1 parent 80d782f commit 4570d3d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
10 changes: 7 additions & 3 deletions CHANGELOG.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
<strong>110005.0-release (2024/11/03)</strong>
<strong>110005.1-release (2024/11/03)</strong>
<ul>
<li>Added option to disable aura on pet nameplates (https://github.com/casualshammy/NameplateAuras/issues/244)</li>
<li>TOC update</li>
<li>Fixed Lua error caused by empty guid for some units</li>
</ul>
<br>
<details>
<summary>Previous versions</summary>
<strong>110005.0-release (2024/11/03)</strong>
<ul>
<li>Added option to disable aura on pet nameplates (https://github.com/casualshammy/NameplateAuras/issues/244)</li>
<li>TOC update</li>
</ul>
<strong>110002.10-release (2024/10/13)</strong>
<ul>
<li>Added option to select instance types for dispellable auras (https://github.com/casualshammy/NameplateAuras/issues/240)</li>
Expand Down
2 changes: 1 addition & 1 deletion src/NameplateAuras.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,7 @@ do
local unitIsFriend = (UnitReaction("player", unitID) or 0) > 4; -- 4 = neutral
local unitIsPlayer = UnitIsPlayer(unitID);
local unitGUID = UnitGUID(unitID);
local unitType = GetUnitTypeByGuid(unitGUID);
local unitType = GetUnitTypeByGuid(unitGUID, unitID);

local iconGroupsToUpdate = {};
for iconGroupIndex, iconGroup in pairs(db.IconGroups) do
Expand Down
18 changes: 15 additions & 3 deletions src/utils.lua
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
-- luacheck: no max line length
-- luacheck: globals LibStub WorldFrame format StaticPopup_Show StaticPopupDialogs CreateFrame debugprofilestop UIParent UNKNOWN DEFAULT_CHAT_FRAME
-- luacheck: globals OKAY YES NO ReloadUI GetPlayerInfoByGUID UnitName GetUnitName wipe C_Spell
-- luacheck: globals OKAY YES NO ReloadUI GetPlayerInfoByGUID UnitName GetUnitName wipe C_Spell UnitIsPlayer

local _, addonTable = ...;
local L = LibStub("AceLocale-3.0"):GetLocale("NameplateAuras");
local SML = LibStub("LibSharedMedia-3.0");
SML:Register("font", "NAuras_TeenBold", "Interface\\AddOns\\NameplateAuras\\media\\teen_bold.ttf", 255);
SML:Register("font", "NAuras_TexGyreHerosBold", "Interface\\AddOns\\NameplateAuras\\media\\texgyreheros-bold-webfont.ttf", 255);
local pairs, select, string_format, string_find = pairs, select, format, string.find;
local GetSpellTexture, GetSpellInfo, GetPlayerInfoByGUID, GetUnitName, wipe = C_Spell.GetSpellTexture, C_Spell.GetSpellInfo, GetPlayerInfoByGUID, GetUnitName, wipe;
local GetSpellTexture, GetSpellInfo, GetPlayerInfoByGUID, GetUnitName, wipe, UnitIsPlayer = C_Spell.GetSpellTexture, C_Spell.GetSpellInfo, GetPlayerInfoByGUID, GetUnitName, wipe, UnitIsPlayer;
local UNIT_TYPE_PLAYER, UNIT_TYPE_NPC, UNIT_TYPE_PET = addonTable.UNIT_TYPE_PLAYER, addonTable.UNIT_TYPE_NPC, addonTable.UNIT_TYPE_PET;
local p_unitNameByGuid = { };
local p_unitTypeByGuid = { };
Expand Down Expand Up @@ -179,12 +179,24 @@ function addonTable.GetOrAddUnitNameByGuid(_unitGuid, _unitId)
end
end

function addonTable.GetUnitTypeByGuid(_unitGuid)
function addonTable.GetUnitTypeByGuid(_unitGuid, _unitId)
local cachedType = p_unitTypeByGuid[_unitGuid];
if (cachedType ~= nil) then
return cachedType;
end

if (_unitGuid == nil) then
if (_unitId == nil) then
return UNIT_TYPE_NPC;
end

if (UnitIsPlayer(_unitId)) then
return UNIT_TYPE_PLAYER;
else
return UNIT_TYPE_NPC;
end
end

if (string_find(_unitGuid, "Player-") == 1) then
p_unitTypeByGuid[_unitGuid] = UNIT_TYPE_PLAYER;
return UNIT_TYPE_PLAYER;
Expand Down

0 comments on commit 4570d3d

Please sign in to comment.