Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 25 additions & 9 deletions Core/MultiBotEngine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,22 @@ MultiBot.isUnit = function(pUnit)
return true
end

-- Safe texture resolver to avoid calling string.sub on nil and to normalize paths
-- Returns a usable texture path string. Falls back to the question mark icon.
MultiBot.SafeTexturePath = function(pTexture)
-- Guard: nil or non-string => fallback
if type(pTexture) ~= "string" or pTexture == "" then
return "Interface/Icons/INV_Misc_QuestionMark"
end
-- Normalize: only prefix when not already an Interface path
local head = string.sub(pTexture, 1, 9)
local needsPrefix = string.lower(head) ~= "interface"
if needsPrefix then
return "Interface/Icons/" .. pTexture
end
return pTexture
end

--[[MultiBot.toClass = function(pClass)
local pLower = string.lower(pClass)
local pStart = string.sub(pLower, 1, 5)
Expand Down Expand Up @@ -593,7 +609,7 @@ MultiBot.newFrame = function(pParent, pX, pY, pSize, oWidth, oHeight, oAlign)
frame.addTexture = function(pTexture)
if(frame.texture ~= nil) then frame.texture:Hide() end
frame.texture = frame:CreateTexture(nil, "BACKGROUND")
frame.texture:SetTexture(MultiBot.IF(string.sub(pTexture, 1, 9) ~= "Interface", "Interface/Icons/", "") .. pTexture)
frame.texture:SetTexture(MultiBot.SafeTexturePath(pTexture))
frame.texture:SetAllPoints(frame)
frame.texture:Show()
return frame.texture
Expand Down Expand Up @@ -670,7 +686,7 @@ MultiBot.newFrame = function(pParent, pX, pY, pSize, oWidth, oHeight, oAlign)
end

frame.setTexture = function(pTexture)
frame.texture:SetTexture(MultiBot.IF(string.sub(pTexture, 1, 9) ~= "Interface", "Interface/Icons/", "") .. pTexture)
frame.texture:SetTexture(MultiBot.SafeTexturePath(pTexture))
frame.texture:SetAllPoints(frame)
frame.texture:Show()
return frame
Expand Down Expand Up @@ -759,7 +775,7 @@ MultiBot.newButton = function(pParent, pX, pY, pSize, pTexture, pTip, oTemplate)
button:Show()

button.icon = button:CreateTexture(nil, "BACKGROUND")
button.icon:SetTexture(MultiBot.IF(string.sub(pTexture, 1, 9) ~= "Interface", "Interface/Icons/", "") .. pTexture)
button.icon:SetTexture(MultiBot.SafeTexturePath(pTexture))
button.icon:SetAllPoints(button)
button.icon:Show()

Expand All @@ -775,7 +791,7 @@ MultiBot.newButton = function(pParent, pX, pY, pSize, pTexture, pTip, oTemplate)
button:SetPushedTexture("Interface/Buttons/UI-Quickslot-Depress")
button:SetNormalTexture("")

button.texture = pTexture
button.texture = MultiBot.SafeTexturePath(pTexture)
button.parent = pParent
button.size = pSize
button.tip = pTip
Expand All @@ -800,17 +816,17 @@ MultiBot.newButton = function(pParent, pX, pY, pSize, pTexture, pTip, oTemplate)
end

button.setButton = function(pTexture, pTip)
button.icon:SetTexture(MultiBot.IF(string.sub(pTexture, 1, 9) ~= "Interface", "Interface/Icons/", "") .. pTexture)
button.icon:SetTexture(MultiBot.SafeTexturePath(pTexture))
button.icon:SetAllPoints(button)
button.texture = pTexture
button.texture = MultiBot.SafeTexturePath(pTexture)
button.tip = pTip
return button
end

button.setTexture = function(pTexture)
button.icon:SetTexture(MultiBot.IF(string.sub(pTexture, 1, 9) ~= "Interface", "Interface/Icons/", "") .. pTexture)
button.icon:SetTexture(MultiBot.SafeTexturePath(pTexture))
button.icon:SetAllPoints(button)
button.texture = pTexture
button.texture = MultiBot.SafeTexturePath(pTexture)
return button
end

Expand Down Expand Up @@ -1320,4 +1336,4 @@ end

MultiBot.getBot = function(pName)
return MultiBot.frames["MultiBar"].frames["Units"].buttons[pName]
end
end
7 changes: 6 additions & 1 deletion UI/MultiBotItem.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ MultiBot.addItem = function(pFrame, pInfo)
local tIcon = GetItemIcon(tID)
local tName, tLink, tRare = GetItemInfo(tID)

-- Fallback icon if not cached/known yet
if tIcon == nil or tIcon == "" then
tIcon = MultiBot.SafeTexturePath("INV_Misc_QuestionMark")
end

local tX = (pFrame.index%8) * 38
local tY = math.floor(pFrame.index/8) * -37.1

Expand Down Expand Up @@ -94,4 +99,4 @@ MultiBot.addItem = function(pFrame, pInfo)
end

pFrame.index = pFrame.index + 1
end
end