View Single Post
11/06/16, 11:03 AM   #1
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,578
attempt to access a private function 'UseItem' from insecure code

I finally took the time to investigate the old "attempt to access a private function 'UseItem' from insecure code" error.
The issue can be reliably reproduced when opening a container via the keybind, closing it and then reopening it again without moving the mouse away from the item while AdvancedFilters is active.
I picked the code apart and disabled it part by part, line by line and finally found that the issue happens when PLAYER_INVENTORY:UpdateList is called from an addon.
More precisly it happens when self:ApplySort is called inside that method. My guess is that ZO_ScrollList_Commit breaks the secure context for the keybind when it autoselects the inventory item entry.

Maybe ZOS could add a new method RequestPlayerInventoryUpdate or something which allows us to call this from a secure context.
Until a better solution is found, I suggest addon authors use the following method instead of directly calling PLAYER_INVENTORY:UpdateList.

Lua Code:
  1. local function SafeUpdateList(object, ...)
  2.     local isMouseVisible = SCENE_MANAGER:IsInUIMode()
  3.  
  4.     --if the mouse is visible, cycle its visibility to refresh the integrity of the control beneath it
  5.     if isMouseVisible then HideMouse() end
  6.  
  7.     object:UpdateList(...)
  8.  
  9.     if isMouseVisible then ShowMouse() end
  10. end
  11.  
  12. -- example usage for different inventories:
  13. SafeUpdateList(PLAYER_INVENTORY, INVENTORY_BACKPACK)
  14. SafeUpdateList(STORE_WINDOW)

Last edited by sirinsidiator : 11/07/16 at 04:29 PM. Reason: replaced code with a better solution found by Randactyl
  Reply With Quote