View Single Post
12/05/14, 09:25 PM   #4
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
Just going through the code and writing down findings... ... ... Ok now that I got through it, you can skip down to the bad button
I'll leave the whole journey here, may be useful another day.

The v[1] from tButtons in your iteration is a control created from ZO_MenuBarButtonTemplate1 by default, but different windows override it with their own template (hopefully always derived from the default). The default template's OnInitialized handler calls ZO_MenuBarButtonTemplate_OnInitialized(self). There it creates an instance of class MenuBarButton:

Lua Code:
  1. function ZO_MenuBarButtonTemplate_OnInitialized(self)
  2.     self.m_object = MenuBarButton:New(self)
  3. end
  4.  
  5. function MenuBarButton:Initialize(button)
  6.     self.m_button = button
  7.     ...
  8. end
  9.  
  10. function MenuBarButton:SetData(owner, buttonData)
  11.     self.m_buttonData = buttonData
  12.    ...
  13. end

So you can get the object from the control, and the control from the object:
Lua Code:
  1. local buttonControl = v[1]
  2. -- this should always be true
  3. assert(buttonControl == buttonControl.m_object.m_button)

m_clickedButton is an instance of MenuBarButton


*** bad button ***

It's quite unfortunate the callback only gets buttonData as the argument. buttonData.control is not coming from the MenuBarButton class, it is set in local function InitializeInventoryFilters(inventory) (ingame/inventory/inventory.lua), i.e. once when the buttons are created. But later, in ZO_InventoryManager:ApplyBackpackLayout, the buttons are released, and some of them acquired from the pool again, but .control is not re-assigned. And that is the problem - buttonData remains the same, but gets attached to a different button control.

It's a bug in ZO_InventoryManager:ApplyBackpackLayout in the loop containing ZO_MenuBar_AddButton calls. Since MenuBarButton class is only accessible via metatables of existing buttons, the simplest fix will probably be replacing ZO_MenuBar_AddButton:
Lua Code:
  1. function ZO_MenuBar_AddButton(self, buttonData)
  2.     local button = self.m_object:AddButton(buttonData)
  3.     buttonData.control = button
  4.     return button
  5. end
  Reply With Quote