TheKrowi / Krowi_Vendorer

1 stars 0 forks source link

Tooltip processing causes game freeze #25

Closed filliph closed 1 year ago

filliph commented 1 year ago

Due to the fact that you use the old method of hooking GameTooltip instead of the new Tooltip Processor, performing an operation such as selling all the blue items in my bags here:

image -> image

Then sorting the inventory causes the game to lock up for approx. 45 seconds.

Yes, it's true that this wouldn't happen with only KV enabled, but literally no-one installing this add-on is going to use this as their only add-on.

You can restore the tooltip via this change:

local function ProcessItem100002(tooltip, localData)
    if tooltip ~= _G.GameTooltip then
        return
    end

    local _, itemLink = tooltip:GetItem();
    ProcessItem(tooltip, itemLink);

--     -- for i, v in next, localData do
--     --     print(i, v)
--     -- end
end

function tooltip.Load()
    TooltipDataProcessor.AddTooltipPostCall(Enum.TooltipDataType.Item, ProcessItem100002);

    -- Enable this again to show tooltip info
    -- hooksecurefunc(GameTooltip, "SetBagItem", function(self, bag, slot)
        -- ProcessItem(self, bag, slot);
    -- end);
end
local function ProcessItem(_tooltip, itemLink)
    if not itemLink then
        return;
    end

    local itemName, _, itemQuality, itemLevel, itemMinLevel, itemType, itemSubType,
    itemStackCount, itemEquipLoc, itemTexture, sellPrice, classID, subclassID, bindType,
    expacID, setID, isCraftingReagent = GetItemInfo(itemLink);

I can confirm the freeze does not happen when using the above code, and the tooltip still works.

filliph commented 1 year ago

Proof that the tooltip still works with this change:

image

TheKrowi commented 1 year ago

Kinda weird that GameTooltip.SetBagItem gets called when refreshing the inventory. I need to find a solution for the old method cause Wrath Classic and probably Classic also (if I want to support it) will use this one most likely. For DF indeed I need to use the proper reworked call.

TheKrowi commented 1 year ago

Caused by calling SetBagItem in https://www.townlong-yak.com/framexml/live/ContainerFrame.lua#1482

TheKrowi commented 1 year ago

TooltipDataProcessor.AddTooltipPostCall(Enum.TooltipDataType.Item, ProcessItem100002); does not easily provide bag and slot info needed for the item location now used for checking soulbound items.

filliph commented 1 year ago

The following code is working for 0.4a1:

function tooltip.Load()
    if addon.IsDragonflightRetail then
        TooltipDataProcessor.AddTooltipPostCall(Enum.TooltipDataType.Item, ProcessItem100002);
        return;
    else
        hooksecurefunc(GameTooltip, "SetBagItem", function(self, bag, slot)
            if addon.Options.db.Tooltip.ShowAutoSellRules then
                ProcessItem(self, bag, slot);
            end
        end);
    end
end
local function ProcessItem100002(tooltip, localData)
    if localData.guid then
        local itemLocation = C_Item.GetItemLocation(localData.guid);
        if itemLocation and itemLocation:IsBagAndSlot() then
            ProcessItem(tooltip, itemLocation.bagID, itemLocation.slotIndex);
        end
    end

    -- if localData.guid then
    --     local itemLink = C_Item.GetItemLinkByGUID(localData.guid);
    -- end
    -- for i, v in next, localData do
    --     print(i, v)
    -- end
end

The following test cases have been verified:

TheKrowi commented 1 year ago

this should be fixed now in the latest dev