Thread Tools Display Modes
11-21-21, 06:24 PM   #1
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Two related errors that are confusing me

Attached is the retail zip of RepByZone in progress. As it stands, I'm getting the following error:
Lua Code:
  1. 5x stack overflow
  2. [string "=[C]"]: in function `GetBestMapForUnit'
  3. [string "@RepByZone\Core-Retail.lua"]:444: in function `SwitchedZones'
  4. [string "@RepByZone\Core-Retail.lua"]:329: in function `CheckSholazarBasin'
  5. [string "@RepByZone\Data-Retail.lua"]:13: in function `ZoneAndFactionList'
  6. [string "@RepByZone\Core-Retail.lua"]:450: in function `SwitchedZones'
  7. [string "@RepByZone\Core-Retail.lua"]:329: in function `CheckSholazarBasin'
  8. [string "@RepByZone\Data-Retail.lua"]:13: in function `ZoneAndFactionList'
  9. [string "@RepByZone\Core-Retail.lua"]:450: in function `SwitchedZones'
  10. [string "@RepByZone\Core-Retail.lua"]:329: in function `CheckSholazarBasin'
  11. [string "@RepByZone\Data-Retail.lua"]:13: in function `ZoneAndFactionList'
  12. [string "@RepByZone\Core-Retail.lua"]:450: in function `SwitchedZones'
  13. [string "@RepByZone\Core-Retail.lua"]:329: in function `CheckSholazarBasin'
  14. ...
  15. [string "=[C]"]: ?
  16. [string "@ElvUI_SLE\core\toolkit.lua"]:265: in function `InitializeModules'
  17. [string "@ElvUI_SLE\core\core.lua"]:126: in function `?'
  18. [string "@ElvUI\Core\Libraries\LibElvUIPlugin-1.0\LibElvUIPlugin-1.0-38.lua"]:306: in function <...\Libraries\LibElvUIPlugin-1.0\LibElvUIPlugin-1.0.lua:302>
  19. [string "=[C]"]: in function `Initialize'
  20. [string "@ElvUI\Core\init.lua"]:168: in function <ElvUI\Core\init.lua:167>
  21. [string "=[C]"]: ?
  22. [string "@Ace3\AceAddon-3.0\AceAddon-3.0-13.lua"]:70: in function <Ace3\AceAddon-3.0\AceAddon-3.0.lua:65>
  23. [string "@Ace3\AceAddon-3.0\AceAddon-3.0-13.lua"]:527: in function `EnableAddon'
  24. [string "@Ace3\AceAddon-3.0\AceAddon-3.0-13.lua"]:630: in function <Ace3\AceAddon-3.0\AceAddon-3.0.lua:615>
The function RepByZone:SwitchedZones() is where the problems lie, and I can't figure them out. In that function, I added the following lines, which seem to be causing the stack overflow. These lines did not exist previously, because the tables are assigned values in the OnEnable() function.
Lua Code:
  1. instancesAndFactions = instancesAndFactions or self:InstancesAndFactionList()
  2. zonesAndFactions = zonesAndFactions or self:ZoneAndFactionList()
  3. subZonesAndFactions = subZonesAndFactions or self:SubZonesAndFactions()
However, if I remove those lines in SwitchedZones(), I get the error below, which didn't exist until two days ago. Again, this doesn't make sense to me, since the tables are not nil.
Lua Code:
  1. 5x RepByZone\Core-Retail.lua:452: bad argument #1 to 'pairs' (table expected, got nil)
  2. [string "=[C]"]: in function `pairs'
  3. [string "@RepByZone\Core-Retail.lua"]:452: in function `SwitchedZones'
  4. [string "@RepByZone\Core-Retail.lua"]:329: in function `CheckSholazarBasin'
  5. [string "@RepByZone\Data-Retail.lua"]:13: in function `ZoneAndFactionList'
  6. [string "@RepByZone\Core-Retail.lua"]:152: in function <RepByZone\Core-Retail.lua:140>
  7. [string "=[C]"]: ?
  8. [string "@Ace3\AceAddon-3.0\AceAddon-3.0-13.lua"]:70: in function <Ace3\AceAddon-3.0\AceAddon-3.0.lua:65>
  9. [string "@Ace3\AceAddon-3.0\AceAddon-3.0-13.lua"]:527: in function `EnableAddon'
  10. [string "@Ace3\AceAddon-3.0\AceAddon-3.0-13.lua"]:630: in function <Ace3\AceAddon-3.0\AceAddon-3.0.lua:615>
  11. [string "=[C]"]: in function `LoadAddOn'
  12. [string "@ElvUI_SLE\modules\professions\professions.lua"]:38: in function <ElvUI_SLE\modules\professions\professions.lua:35>
  13. [string "=[C]"]: ?
  14. [string "@ElvUI_SLE\core\toolkit.lua"]:265: in function `InitializeModules'
  15. [string "@ElvUI_SLE\core\core.lua"]:126: in function `?'
  16. [string "@ElvUI\Core\Libraries\LibElvUIPlugin-1.0\LibElvUIPlugin-1.0-38.lua"]:306: in function <...\Libraries\LibElvUIPlugin-1.0\LibElvUIPlugin-1.0.lua:302>
  17. [string "=[C]"]: in function `Initialize'
  18. [string "@ElvUI\Core\init.lua"]:168: in function <ElvUI\Core\init.lua:167>
  19. [string "=[C]"]: ?
  20. [string "@Ace3\AceAddon-3.0\AceAddon-3.0-13.lua"]:70: in function <Ace3\AceAddon-3.0\AceAddon-3.0.lua:65>
  21. [string "@Ace3\AceAddon-3.0\AceAddon-3.0-13.lua"]:527: in function `EnableAddon'
  22. [string "@Ace3\AceAddon-3.0\AceAddon-3.0-13.lua"]:630: in function <Ace3\AceAddon-3.0\AceAddon-3.0.lua:615>
I honestly do not understand why either error exists, nor do I understand how to fix them. The three extra lines do not exist in the copy that users would download and install, and there are no errors in that version. The difference is that I added Warlords of Draenor data, and an option for the user to choose between watching the assigned zone factions or their bodyguard's faction, if a bodyguard is applied to the baracks.

Please send help! I've run out of ideas.
Attached Files
File Type: zip RepByZone.zip (280.5 KB, 101 views)
  Reply With Quote
11-21-21, 07:28 PM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
Somewhere, adding the extra lines has created a recursive call that gets back to RepByZone:SwitchedZones()

Simple check, change:
Code:
function RepByZone:SwitchedZones()
to:
Code:
local count = 0
function RepByZone:SwitchedZones()
count = count + 1
print("count", count)
And see how many times you end up in the same place before it errors.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 11-21-21 at 10:20 PM.
  Reply With Quote
11-22-21, 06:25 AM   #3
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
Originally Posted by myrroddin View Post
[string "@RepByZone\Core-Retail.lua"]:329: in function `CheckSholazarBasin'
[string "@RepByZone\Data-Retail.lua"]:13: in function `ZoneAndFactionList'
[string "@RepByZone\Core-Retail.lua"]:450: in function `SwitchedZones'
From these 3 lines repeating near the top of the stack, this indicates an infinite loop.
This is triggered both from RepByZone:OnEnable() calling RepByZone:ZoneAndFactionList() and your events calling RepByZone:SwitchedZones().



Originally Posted by myrroddin View Post
However, if I remove those lines in SwitchedZones(), I get the error below, which didn't exist until two days ago. Again, this doesn't make sense to me, since the tables are not nil.
The variable in question is indeed nil, but to explain, we'll walk through the call stack.
[string "=[C]"]: in function `pairs'
[string "@RepByZone\Core-Retail.lua"]:452: in function `SwitchedZones'
[string "@RepByZone\Core-Retail.lua"]:329: in function `CheckSholazarBasin'
[string "@RepByZone\Data-Retail.lua"]:13: in function `ZoneAndFactionList'
[string "@RepByZone\Core-Retail.lua"]:152: in function <RepByZone\Core-Retail.lua:140>
The first entry points to this line in RepByZone:OnEnable().
Code:
zonesAndFactions = self:ZoneAndFactionList()
The error occurs while running RepByZone:ZoneAndFactionList() so the variable (and others following it) doesn't actually get set.

This continues on to RepByZone:CheckSholazarBasin(), which proceeds with calling RepByZone:SwitchedZones(). Note this function hasn't returned yet either and continues holding up the line.

Now RepByZone:SwitchedZones() is running, but because neither of the functions have had the ability to return yet, subZonesAndFactions (to be set after zonesAndFactions in RepByZone:OnEnable()) is still nil.



I suggest removing self:SwitchedZones() from RepByZone:CheckSholazarBasin(). That one line is what's causing all of your problems. If you need to call RepByZone:SwitchedZones() from RepByZone:OnEnable(), put it in there.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
11-22-21, 07:34 AM   #4
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Whew. Thank you SDPhantom. That was driving me crazy. Do I need to/should I be calling self:SwitchedZones() in Options.lua? I can't tell if that is causing a stack overflow that isn't being caught, as commenting out the lines or leaving them in doesn't seem to make BugSack unhappy.

Also, now that I no longer have any errors, something else is confusing me. After your explanation, I fixed the code in self:CheckSolazarBasin(). So far so good.... until I zoned into my garrison.

Once there, I still don't get any errors (woot~ ) but now my bodyguard's faction isn't being set as the watched faction. My Night Elf Demon Hunter is watching Darnassus in both the garrison and the mine/excavation. Heading out to Shadowmoon Valley watches Council of Exarchs, which would be correct if I wasn't supposed to be watching Delvar Ironfist.

So, the code is ignoring the bodyguards. Hm, okay. But why?

Attached is the updated zip.
Attached Files
File Type: zip RepByZone.zip (280.7 KB, 126 views)
  Reply With Quote
11-24-21, 02:11 AM   #5
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
Originally Posted by myrroddin View Post
Do I need to/should I be calling self:SwitchedZones() in Options.lua? I can't tell if that is causing a stack overflow that isn't being caught, as commenting out the lines or leaving them in doesn't seem to make BugSack unhappy.
If any particular option changes the behavior of RepByZone:SwitchedZones(), then go ahead and call it. The stack overflow was caused by the infinite loop we just fixed.



Originally Posted by myrroddin View Post
Also, now that I no longer have any errors, something else is confusing me. After your explanation, I fixed the code in self:CheckSolazarBasin(). So far so good.... until I zoned into my garrison.

Once there, I still don't get any errors (woot~ ) but now my bodyguard's faction isn't being set as the watched faction. My Night Elf Demon Hunter is watching Darnassus in both the garrison and the mine/excavation. Heading out to Shadowmoon Valley watches Council of Exarchs, which would be correct if I wasn't supposed to be watching Delvar Ironfist.
This line in RepByZone:SwitchedZones() stands out to me.
Code:
local isWoDZone = #self.WoDFollowerZones > 0 and self.WoDFollowerZones[UImapID] or self.WoDFollowerZones[parentMapID]
The table is defined with this.
Code:
RepByZone.WoDFollowerZones = {
    [525]   = true, -- Frostfire Ridge
    [534]   = true, -- Tanaan Jungle
    [535]   = true, -- Talador
    [539]   = true, -- Shadowmoon Valley
    [542]   = true, -- Spires of Arak
    [543]   = true, -- Gorgrond
    [550]   = true, -- Nagrand
    [579]   = true, -- Lunarfall Excavation 1
    [580]   = true, -- Lunarfall Excavation 2
    [581]   = true, -- Lunarfall Excavation 3
    [582]   = true, -- Lunarfall
    [585]   = true, -- Frostwall Mine 1
    [586]   = true, -- Frostwall Mine 2
    [587]   = true, -- Frostwall Mine 3
    [588]   = true, -- Ashran
    [590]   = true, -- Frostwall
}
The problem is the length operator (#) only operates on sequential indices, meaning it'll always return zero in your code. You could just remove the length check and let the lookup do its work anyway.



Another unrelated issue is you should reinitialize your data tables when a Pandaren chooses their faction. Otherwise, the faction-specific reps won't load correctly. The following additions should correct this.
Code:
function RepByZone:CheckPandaren(event, success)
	if success then
		A = UnitFactionGroup("player") == "Alliance" and ALLIANCE
		H = UnitFactionGroup("player") == "Horde" and HORDE
		if UnitFactionGroup("player") ~= nil then
			instancesAndFactions = self:InstancesAndFactionList()
			zonesAndFactions = self:ZoneAndFactionList()
			subZonesAndFactions = self:SubZonesAndFactions()

			self:GetRacialRep()
			if db.watchedRepID == 1216 then
				db.watchedRepID, db.watchedRepName = self:GetRacialRep()
				self:Print(L["You have joined the faction %s, switching watched saved variable to %s."]:format(A or H, db.watchedRepName))
				self:SwitchedZones()
			end
		end
	end
	if A or H then
		self:UnregisterEvent(event)
	end
end
Looks like CitySubZonesAndFactions is also affected by this bug, but is not accessible by this function because the local is defined later in the file.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 11-24-21 at 02:41 AM.
  Reply With Quote
11-25-21, 03:46 AM   #6
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Attached is the latest zip with all the file changes.
  • Moved RepByZone.WoDFollowerZones to the top of Core-Retail.lua
  • Moved CitySubZonesAndFactions to the top of the file
  • Removed table length operator
  • Reinitialized data tables in CheckPandaren() and JoinedCovenant()
  • Refactored GetRacialRep() to correctly assign a default reputation if all others are unknown
  • Added debug prints in SwitchedZones()
  • Disabled watched bodyguard WoD zones in Options.lua if no bodyguard exists
  • Fixed bodyguard returned factions to factionID numbers, was strings before
This is what I found out:
  1. When in WoD zones, with the option enabled, or disabled code commented out, the print correctly says true. When the options are set to false, the print is nil. That is correct.
  2. If the setting is disabled, either by clicking to false or commenting out the disabled line, RBZ sets WoD zones correctly as per the hard-coded tables.
  3. However, the return for CheckBodyguard() is nil in all cases. I've played around with the return's placement, and so far everything I've tried always returns nil.
I'm glad I put the print statements into SwitchedZone(); at least I know the zone tables are working, both if there is a bodyguard and not.

I have the feeling that CheckBodyguard() is returning nil because "Lua doesn't work that way", a mistake I seem to make a lot, given this thread.

For brevity, here's the function by itself. The commented URL is a list of IsQuestCompleted() if the player talks to the bodyguard and says "come with me, I need muscle". I'm not sure if I need to check for quest completion, or if simply assigning the follower to the barracks is enough. If the follower is not actually hanging out with the player, the follower does not gain reputation, so I might have to check.
Lua Code:
  1. -- WoD garrison bodyguard code
  2. local garrFollowerIDToReputationID = {
  3.     -- garrison followerID = factionID
  4.     -- see full list of garrFollowerIDs: [url]https://wowpedia.fandom.com/wiki/GarrFollowerID[/url]
  5.     [193]       = 1736,     -- Tormmok
  6.     [207]       = A and 1738 or H and 1740, -- Defender Illona or Aeda Brightdawn
  7.     [216]       = A and 1733 or H and 1739, -- Delvar Ironfist or Vivianne
  8.     [218]       = 1737,     -- Talonpriest Ishaal
  9.     [219]       = 1741,     -- Leorajh
  10. }
  11.  
  12. -- WoD barracks buildingIDs
  13. local barracks_ids = {
  14.     [27]        = true,     -- level 2
  15.     [28]        = true,     -- level 3
  16. }
  17.  
  18. -- [url]https://www.wowhead.com/quests/garrisons/garrison-support#q=tracking[/url]
  19.  
  20. function RepByZone:CheckBodyguard()
  21.     local bodyguardRep
  22.     local buildings = C_Garrison.GetBuildings(Enum.GarrisonType.Type_6_0)
  23.     for i = 1, #buildings do
  24.         local building = buildings[i]
  25.         local building_id = building.buildingID
  26.         local plot_id = building.plotID
  27.         if barracks_ids[building_id] then
  28.             local name, _, _, _, _, garrFollowerID = C_Garrison.GetFollowerInfoForBuilding(plot_id)
  29.             if name then
  30.                 bodyguardRep = garrFollowerIDToReputationID[garrFollowerID]
  31.             end
  32.             break
  33.         end
  34.         return bodyguardRep
  35.     end
  36.     return bodyguardRep
  37. end
Attached Files
File Type: zip RepByZone.zip (219.2 KB, 80 views)
  Reply With Quote
11-25-21, 03:49 PM   #7
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
The first thing that caught my attention.
Code:
local bodyguardRep = self:CheckBodyguard()
self:Print("DEBUG: The value of bodyguard is", bodyguard)
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Two related errors that are confusing me

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off