ESOUI - View Single Post - Performance Problem with EVENT_LOOT_UPDATED
View Single Post
10/21/21, 08:29 AM   #2
Super Moderator
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 3,815
>I think that the removal of the wanted ones triggers a call of the event EVENT_LOOT_UPDATED again and the function is called again.
You are easily able to find this out by adding a d("EVENT_LOOT_UPDATED") into your callback function

Lua Code:
  1. self.control:RegisterForEvent(EVENT_LOOT_UPDATED, function( _, ... )
  2.    d("-->EVENT_LOOT_UPDATED was called")
  3.    self:OnLootUpdated( ... )  
  4. end)

So you will see in chat how often, and when, it will be called.
I guess it will be called once per update to the loot window which might happen as you remove lines in there, yes. Or maybe even changing the position will call the event for the EVENT_LOOT_UPDATED. Depends on how ZOs implemented this.
maybe another event like EVENT_LOOT_RECEIVED could help here instead, you would have to try though.

If you do not want to let the event callback function self:OnLootUpdated( ... ) run multiple times try to surround it with a blocking/"already currently running" variable like this:

Lua Code:
  1. local lootInProgress = false
  2. self.control:RegisterForEvent(EVENT_LOOT_UPDATED, function( _, ... )
  3.    d("-->EVENT_LOOT_UPDATED was called")
  4.    if lootInProgress then return end
  5.    lootInProgress = true
  6.    self:OnLootUpdated( ... )  
  7.    lootInProgress = false
  8. end)

Should work the same with the unregister of the event, yes.
If this does not work there is something else triggering the code, maybe not via EVENT_LOOT_UPDATED?
Did you check if anything else in the addon calls self:OnLootUpdated function ?
  Reply With Quote