I have a problem with UnregisterEvent when two elements are registering / unregistering the same event on the same frame, here is the scenario where I have my problem:
Element 1:
In the Enable function UNIT_POWER is registered
Element 2:
In the Enable function a Toggle function is called, and this function will Register or Unregister UNIT_POWER based on some condition, in my scenario it's Unregisterded.
The problem is that UNIT_POWER has been Unregistered not for element 2 but for element 1.
Here is how events are Unregistered in oUF events.lua :
Code:
local UnregisterEvent = frame_metatable.__index.UnregisterEvent
function frame_metatable.__index:UnregisterEvent(event, func)
argcheck(event, 2, 'string')
local curev = self[event]
if(type(curev) == 'table' and func) then
for k, infunc in next, curev do
if(infunc == func) then
table.remove(curev, k)
local n = #curev
if(n == 1) then
local _, handler = next(curev)
self[event] = handler
elseif(n == 0) then
UnregisterEvent(self, event)
end
break
end
end
else
self[event] = nil
UnregisterEvent(self, event)
end
end
In my case curev is not a table so it end up in the part in red bold in the code quote above.
I modified my local copy of events.lua (the red bold part) like this
Code:
elseif curev == func then
self[event] = nil
UnregisterEvent(self, event)
end
I haven't done much testing and I may be wrong but it seems that with this change my problem is fixed.
Any thought on this?