From 75e4d83fc01e01bd353b1ba5f1c6769c0dca6f2d Mon Sep 17 00:00:00 2001 From: Salikh Gurgenidze Date: Sat, 24 Jan 2026 00:38:03 +0400 Subject: [PATCH] fix: bug --- Data/BagScanner.lua | 40 +++++++++++++++++++++++++--------------- Data/BankScanner.lua | 35 ++++++++++++++++++++--------------- 2 files changed, 45 insertions(+), 30 deletions(-) diff --git a/Data/BagScanner.lua b/Data/BagScanner.lua index 0928d71..ffd3b77 100644 --- a/Data/BagScanner.lua +++ b/Data/BagScanner.lua @@ -52,24 +52,29 @@ function BagScanner:GetBagData() if cacheValid and bagCache then -- Process any dirty slots incrementally for bagID, slots in pairs(dirtySlots) do - if bagCache[bagID] then - for slotID in pairs(slots) do - local oldData = bagCache[bagID].slots[slotID] - local newData = self:ScanSlot(bagID, slotID) - bagCache[bagID].slots[slotID] = newData + if bagID ~= nil and type(slots) == "table" then + if bagCache[bagID] then + for slotID in pairs(slots) do + -- Validate slotID is a valid number + if type(slotID) == "number" and slotID >= 1 then + local oldData = bagCache[bagID].slots[slotID] + local newData = self:ScanSlot(bagID, slotID) + bagCache[bagID].slots[slotID] = newData - -- Update free slot count - local wasEmpty = (oldData == nil) - local isEmpty = (newData == nil) - if wasEmpty and not isEmpty then - bagCache[bagID].freeSlots = bagCache[bagID].freeSlots - 1 - elseif not wasEmpty and isEmpty then - bagCache[bagID].freeSlots = bagCache[bagID].freeSlots + 1 + -- Update free slot count + local wasEmpty = (oldData == nil) + local isEmpty = (newData == nil) + if wasEmpty and not isEmpty then + bagCache[bagID].freeSlots = bagCache[bagID].freeSlots - 1 + elseif not wasEmpty and isEmpty then + bagCache[bagID].freeSlots = bagCache[bagID].freeSlots + 1 + end + end end + else + -- Bag not in cache, scan it + bagCache[bagID] = self:ScanBag(bagID) end - else - -- Bag not in cache, scan it - bagCache[bagID] = self:ScanBag(bagID) end end dirtySlots = {} @@ -139,6 +144,11 @@ end -- Scan a single slot function BagScanner:ScanSlot(bagID, slot) + -- Validate parameters to prevent API errors + if bagID == nil or slot == nil or slot < 1 then + return nil + end + local texture, itemCount, locked, quality, readable, lootable = GetContainerItemInfo(bagID, slot) if not texture then diff --git a/Data/BankScanner.lua b/Data/BankScanner.lua index f63d8f0..8f8f706 100644 --- a/Data/BankScanner.lua +++ b/Data/BankScanner.lua @@ -52,24 +52,29 @@ function BankScanner:GetBankData() if cacheValid and bankCache then -- Process any dirty slots incrementally for bagID, slots in pairs(dirtySlots) do - if bankCache[bagID] then - for slotID in pairs(slots) do - local oldData = bankCache[bagID].slots[slotID] - local newData = addon.Modules.BagScanner:ScanSlot(bagID, slotID) - bankCache[bagID].slots[slotID] = newData + if bagID ~= nil and type(slots) == "table" then + if bankCache[bagID] then + for slotID in pairs(slots) do + -- Validate slotID is a valid number + if type(slotID) == "number" and slotID >= 1 then + local oldData = bankCache[bagID].slots[slotID] + local newData = addon.Modules.BagScanner:ScanSlot(bagID, slotID) + bankCache[bagID].slots[slotID] = newData - -- Update free slot count - local wasEmpty = (oldData == nil) - local isEmpty = (newData == nil) - if wasEmpty and not isEmpty then - bankCache[bagID].freeSlots = bankCache[bagID].freeSlots - 1 - elseif not wasEmpty and isEmpty then - bankCache[bagID].freeSlots = bankCache[bagID].freeSlots + 1 + -- Update free slot count + local wasEmpty = (oldData == nil) + local isEmpty = (newData == nil) + if wasEmpty and not isEmpty then + bankCache[bagID].freeSlots = bankCache[bagID].freeSlots - 1 + elseif not wasEmpty and isEmpty then + bankCache[bagID].freeSlots = bankCache[bagID].freeSlots + 1 + end + end end + else + -- Bag not in cache, scan it + bankCache[bagID] = self:ScanBankBag(bagID) end - else - -- Bag not in cache, scan it - bankCache[bagID] = self:ScanBankBag(bagID) end end dirtySlots = {}