87 - Patch to fix macro.lua/core.lua ZONE_CHANGED_NEW_AREA event handling conflict
What does the provided patch do?
Currently, it is possible that macro.lua's ZONE_CHANGED_NEW_AREA event handler will fire before the one in core.lua. Thus, when it calls GetPlayerZone it will actually see the cached (previous) zone. This means that the macro created for SilverDragonMacroButton will be trying to target the list of rares (if any) in the previous zone, not the current zone.
This patch purports to fix that, by removing the RegisterEvent declaration for core.lua's handler, and calling core.lua's ZONE_CHANGED_NEW_AREA function directly from macro.lua's ZONE_CHANGED_NEW_AREA event handler. The (possibly wrong) assumption is that macro.lua's handler will always be enabled with the rest of the addon; otherwise, a more elegant solution would need to be found to ensure that currentContinent/currentZone are always set properly before macro.lua's Update() is called.
Additionally, a forced call to macro.lua's ZONE_CHANGED_NEW_AREA was being made from macro.lua's OnInitialize function, perhaps in an attempt to force the macro button to be initialized to the current location's rares. Unfortunately this code was possibly being executed well before the necessary continent/zone information would be obtainable, causing both currentContinent/currentZone to be set to 0. This call is not necessary, as a ZONE_CHANGED_NEW_AREA event will be sent upon player load.
Reflecting this, in core.lua, besides the removal of RegisterEvent("ZONE_CHANGED_NEW_AREA"), currentContinent and currentZone are defaulted to 0, not nil, as the only time GetPlayerZone was executed with both defaulted to nil was again so early (either via the aforementioned forced call or the first CheckNearby call) that the result was to just have both set to 0. The rest of GetPlayerZone serves as a sanity check for unknown values of currentContinent and currentZone anyway so the entire conditional block checking for nil could be, and has been, deleted.
Again, this was just a quick fix to an annoying problem (e.g. in Dalaran or Icecrown, SilverDragonMacroButton's macro text was empty; in Crystalsong, it reflected Vern or the Icecrown rares depending on which zone the player had recently left). You may wish to work out a more appropriate solution to the problem.
core.lua diff
--- core.lua-orig 2011-10-30 15:39:46.000000000 -0400 +++ core.lua 2011-11-10 09:12:13.268472200 -0500 @@ -50,7 +50,6 @@ function addon:OnEnable() self:RegisterEvent("PLAYER_TARGET_CHANGED") self:RegisterEvent("UPDATE_MOUSEOVER_UNIT") - self:RegisterEvent("ZONE_CHANGED_NEW_AREA") if self.db.profile.scan > 0 then self:ScheduleRepeatingTimer("CheckNearby", self.db.profile.scan) end @@ -398,8 +397,8 @@ local continent_list = { GetMapContinents() } local zone_to_mapfile = {} local mapfile_to_zone = {} -local currentContinent = nil -local currentZone = nil +local currentContinent = 0 +local currentZone = 0 for C in pairs(continent_list) do local zones = { GetMapZones(C) } continent_list[C] = zones @@ -447,20 +446,6 @@ if IsInInstance() then return BZR[GetRealZoneText()] end - --Silver dragon loads AFTER first ZONE_CHANGED_NEW_AREA on login, so we need a hack for initial lack of ZONE_CHANGED_NEW_AREA. - if currentContinent == nil and currentZone == nil then - if WorldMapFrame:IsVisible() then--World Map is open - local C, Z = GetCurrentMapContinent(), GetCurrentMapZone()--Save current map settings. - SetMapToCurrentZone() - currentContinent, currentZone = GetCurrentMapContinent(), GetCurrentMapZone()--Get right info after we set map to right place. - if currentContinent ~= C or currentZone ~= Z then - SetMapZoom(C, Z)--Restore old map settings if they differed to what they were prior to forcing mapchange and user has map open. - end - else--Map is not open, no reason to go extra miles, just force map to right zone and get right info. - SetMapToCurrentZone() - currentContinent, currentZone = GetCurrentMapContinent(), GetCurrentMapZone()--Get right info after we set map to right place. - end - end if not (continent_list[currentContinent] and continent_list[currentContinent][currentZone]) then return end
macro.lua diff
--- macro.lua-orig 2011-10-30 15:39:46.000000000 -0400 +++ macro.lua 2011-11-10 08:07:17.397641200 -0500 @@ -41,8 +41,6 @@ }, } end - - self:ZONE_CHANGED_NEW_AREA() end function module:Update() @@ -80,16 +78,19 @@ end function module:ZONE_CHANGED_NEW_AREA(...) + core:ZONE_CHANGED_NEW_AREA() if InCombatLockdown() then self.waiting = true else self:Update() + self.waiting = false end end function module:PLAYER_REGEN_ENABLED() if self.waiting then self:Update() + self.waiting = false end end
Please provide any additional information below.
My testing has been limited to Vern and the Dalaran/Crystalsong/Icecrown route. I'm still wishy-washy on using a tracking addon but like SilverDragon and was irked that the macro button wasn't being populated properly. So hopefully this code helps, or at least points you toward your preferred fix.
| Name | Description | Size | MD5 |
|---|---|---|---|
| macro.lua.patch | macro.lua diff | 570 B | 5f8ed78c4bd8... |
| core.lua.patch | core.lua diff | 1.9 KiB | 64c2f533ad5b... |
| User | When | Change |
|---|---|---|
| Boccanegra | Nov 11, 2011 at 00:56 UTC | Added attachment core.lua.patch |
| Boccanegra | Nov 11, 2011 at 00:56 UTC | Added attachment macro.lua.patch |
| Boccanegra | Nov 10, 2011 at 15:30 UTC | Create |
- 1 comment
- 1 comment
Facts
- Last updated
- Nov 11, 2011
- Reported
- Nov 10, 2011
- Status
- New - Issue has not had initial review yet.
- Type
- Patch - Source code patch for review
- Priority
- Medium - Normal priority.
- Votes
- 0
- Reply
- #1
Boccanegra Nov 11, 2011 at 00:59 UTC - 0 likes(figured it might help to upload the patch files as well)