Thread Tools Display Modes
04-06-11, 08:48 AM   #1
gagou
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 16
problem with UnregisterEvent

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?
  Reply With Quote
04-06-11, 01:26 PM   #2
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 1,027
Confirmed, and your fixed push.
__________________
「貴方は1人じゃないよ」
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » problem with UnregisterEvent


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