Errors when unit is not valid
Road-block opened this issue ยท 5 comments
Needs a guard on Core.lua#L59 that name and unit are valid.
For example
GameTooltip:HookScript("OnTooltipSetUnit", function(self)
local tooltip = self.GetUnit and self or GameTooltip
local name, unit = tooltip:GetUnit()
if (name) and (unit) then
local guid = UnitGUID(unit)
if type(guid)=="string" then
local ctype, _, _, _, _, _, _ = string.split("-", guid);
if ctype == "Creature" then
local factionID = UnitFlavorFaction(unit)
local faction = Factions[factionID] -- GetFactionInfoByID(factionID) does not work for enemy factions
if factionID and ShouldFactionBeAdded(faction) then
-- Find line that starts with "Level" and insert faction after
local levelIndex = FindLine(tooltip, function(line)
return string.sub(line, 1, #"Level") == "Level"
end)
local faction_color = TOOLTIP_DEFAULT_COLOR
if not levelIndex or levelIndex == tooltip:NumLines() then
tooltip:AddLine(faction.name, faction_color.r, faction_color.g, faction_color.b)
else
local faction_index = levelIndex + 1
InsertLine(tooltip, faction_index, faction.name, faction_color.r, faction_color.g, faction_color.b)
end
end
end
end
end
end)
will work without errors.
Hello Road-block. Thank you for reporting this.
Did you encounter errors related to this in-game?
In which scenario can they happen?
I did yes, I'm not sure how to give you a repro they do not happen on every mob.
For a time I thought it might be npcs with a creature type of "not specified" (for example silithid) but I'm not sure what triggers it.
Blizzard is using a similar nil-guard in their interface code so I'm guessing there's known situations where OnTooltipSetUnit doesn't guarantee a valid :GetUnit() return.
I've probably seen it more in aoe farming when mouse-overing a bunch of mobs in a very short time.
Even with the code above ..
1x FlavorFactions\Core.lua:62: bad argument #2 to 'split' (string expected, got nil)
[C]:: in function 'split'
FlavorFactions\Core.lua:62: in function <FlavorFactions\Core.lua:57
But I think I know how this is possible... The unit
token passed to UnitGUID()
was invalidated by crossing a portal.
Final revision above, edited again. Should be impossible to error now ๐
Fixed by commit 3843253 .
Thanks Road-block!