Thread Tools Display Modes
10/28/20, 12:00 PM   #1
nightdreaming
Join Date: Feb 2018
Posts: 8
AddFilterForEvent - unable to UnregisterForEvent

I am having a problem de-registering an event for which I have added a filter. For example:

Code:
EVENT_MANAGER:RegisterForEvent("myEvent1", EVENT_COMBAT_EVENT, myEventHandler) 
EVENT_MANAGER:AddFilterForEvent("myEvent1", EVENT_COMBAT_EVENT, REGISTER_FILTER_TARGET_COMBAT_UNIT_TYPE, COMBAT_UNIT_TYPE_PLAYER)
The above works fine, if I switch my bar to one that has Crystal Fragments on it then I get an event saying ACTION_RESULT_EFFECT_GAINED "Crystal Fragments Passive", which is what I would expect (as the target of it is me). If I switch bar away from that I also get ACTION_RESULT_EFFECT_FADED "Crystal Fragments Passive" as I would expect.

The problem I am having is if I want to change what events I am getting, for example if I want all combat events instead of just those where I am the target (note this is a change without reloadui, so just a different section of my code). My code does this:

Code:
EVENT_MANAGER:UnregisterForEvent("myEvent1", EVENT_COMBAT_EVENT) 
EVENT_MANAGER:RegisterForEvent("myEvent1", EVENT_COMBAT_EVENT, myEventHandler) 
This should remove the old event registration and replace it. But it doesn't. I still get the same events triggered, for example when I switch bar. It seems as if unregistering the event doesn't actually unregister the filter.

Has anyone come across this, or have any thoughts?
  Reply With Quote
10/28/20, 12:40 PM   #2
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
As the filtering does not happen in lua code it could be that unregistering an event via lua does not remove the filters on it.
Maybe event filters will only clear on reloadui and are designed to be used that way.
This is something you should ask to ZOs.

Did you try to just overwrite the existing one without unregistering it, does it keep the filter as well? (I assume this would be intended, where your usecase though would be "an error").


Just use another unique identifier for new registered events and do not re-use your before used myEvent1. I actually always counted +1 and registered the same event's filters this way, if there is no other unique eventName portion like the abilityId or some other Id available. But even then I think I counted a variable + 1 and added it as string via
Code:
eventName.."_"..counterVar
at the end to make sure I do not alter or re-register some already registered event + filter.

Last edited by Baertram : 10/28/20 at 12:42 PM.
  Reply With Quote
10/28/20, 01:23 PM   #3
nightdreaming
Join Date: Feb 2018
Posts: 8
Thanks Baertram, I reduced my code to make it more readable, I am registering events and filters using a counter on the namespace as you suggest, that all works fine.

I am trying to unregister and then re-use the unregistered namespace, but that gives the behaviour above. If I unregister the old namespace and then using a different namespace for the new event, I do get the new events, but I also continue to get the old events I don't want any more. As a developer, it offends me to leave things hanging around that are no longer being used :-) Hence my preference to unregisters events+filters I don't use any more.

It probably isn't unregistering the filters in the C code. Oh well...
  Reply With Quote
10/29/20, 09:50 AM   #4
ZOS_DanBatson
ZOS Staff!
 
ZOS_DanBatson's Avatar
Yes this person is from ZeniMax!
Join Date: Jul 2015
Posts: 171
I put in a fix, but it won't make it in until the next major update (not the one coming next week, but the one after that, update 29.) The issue specifically happens if you unregister and register again in the same frame. In the mean time you can alleviate this by waiting a frame before doing the re-register.
  Reply With Quote
10/29/20, 10:34 AM   #5
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
Just as an extra info (maybe there is a better way as well to achieve this?):
To wait 1 frame just call your function with a zo_callLater and delay 0 ms:

Code:
zo_callLater(function() 
   -- run you code which should be delayed by 1 frame here
end, 0)
  Reply With Quote
11/01/20, 07:15 PM   #6
Solinur
AddOn Author - Click to view addons
Join Date: Aug 2014
Posts: 78
Thanks for the report an the nice explanation!
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » AddFilterForEvent - unable to UnregisterForEvent

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