tropicdome / MyPetBattle

6 stars 7 forks source link

bug: C_PetJournal.GetPetLoadOutInfo returns nil at startup #16

Closed joevt closed 11 years ago

joevt commented 11 years ago

I get the error below when I first login to WoW. It doesn't appear to happen when I do /reloadui.

The fix is to check petGUID for nil value after the call to C_PetJournal.GetPetLoadOutInfo in events:PET_JOURNAL_LIST_UPDATE.

Another issue is that events:PET_JOURNAL_LIST_UPDATE seems to be called once per second. That's not a big problem since once per second is not very frequent. If it can't be fixed and SetTexture or SetText takes any amount of time, then maybe cache petGUID for each slot and don't call SetTexture and SetText unless the petGUID changed.

local nilguidcount = 0
local petguids = {0,0,0}

function events:PET_JOURNAL_LIST_UPDATE(...)
    -- Set UI textures for current pet team when the UI is loaded -- IS NOT NEEDED ANYMORE SINCE setTeam() IS CALLED ABOVE, AND THAT FUNCTION SETS THE TEXTURES
    -- MIGHT BE NEEDED ANYWAY, IF AUTO NEW TEAM IS ACTIVE, THEN THE TEXTURE WILL NOT BE LOADED ON LOGIN
    for i_ = 1, 3 do
        local petGUID = C_PetJournal.GetPetLoadOutInfo(i_)
        if not petGUID then
            nilguidcount = nilguidcount + 1
            print("nilguidcount", nilguidcount)
        else
            if petguids[i_] ~= petGUID then
                print("petGUID", petGUID)
                petguids[i_] = petGUID
                local speciesID, customName, level, xp, maxXp, displayID, isFavorite, name, icon, petType, creatureID, sourceText, description, isWild, canBattle, tradable, unique, obtainable = C_PetJournal.GetPetInfoByPetID(petGUID) 

                -- Set pet 1 UI texture
                if i_ == 1 then 
                    Pet1_texture:SetTexture(icon) 
                    Pet1_level_string:SetText(level)
                end
                -- Set pet 2 UI texture
                if i_ == 2 then 
                    Pet2_texture:SetTexture(icon) 
                    Pet2_level_string:SetText(level)
                end
                -- Set pet 3 UI texture
                if i_ == 3 then 
                    Pet3_texture:SetTexture(icon) 
                    Pet3_level_string:SetText(level)
                end
            end
        end
    end
end
Date: 2013-07-06 21:53:08
ID: 2
Error occured in: Global
Count: 1
Message: ..\AddOns\MyPetBattle\MyPetBattle.lua line 380:
   Usage: GetPetInfoByID(ID)
Debug:
   [C]: GetPetInfoByPetID()
   MyPetBattle\MyPetBattle.lua:380: ?()
   MyPetBattle\MyPetBattle.lua:578:
      MyPetBattle\MyPetBattle.lua:577
Locals:
(*temporary) = nil
joevt commented 11 years ago

Another reason to check for nil petGUID: what if the user doesn't have 3 pets yet? I haven't tested that case since I'd have to use a new account because pets are account wide. Is there a way to remove a pet from a slot?

tropicdome commented 11 years ago

I have added a check for the nil value. Will be in next update.

I moved the texture update to the 1 sec timer frame instead, because I realized events:PET_JOURNAL_LIST_UPDATE was unreliable for some people, and I found the reason was that some do not get the event every second. I found in my setup the event was actually triggered by the add-on ArkInventory. When I disabled this add-on events:PET_JOURNAL_LIST_UPDATE almost never fired, which was not good. But all this is fixed now.

The case with not having three pets I will not worry too much about. It is such a rare case. I am not sure if you can make a team with just one or two pets. I tried but with no luck, and I really do not see the point :)