ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   General Authoring Discussion (https://www.esoui.com/forums/forumdisplay.php?f=174)
-   -   Access a private function ShowMenu Bug (https://www.esoui.com/forums/showthread.php?t=4613)

votan 04/20/15 12:59 PM

Access a private function ShowMenu Bug
 
Code:

EsoUI/Ingame/Inventory/InventorySlot.lua:903: attempt to access a private function 'PickupInventoryItem' from insecure code
stack traceback:
EsoUI/Ingame/Inventory/InventorySlot.lua:903: in function 'InitiateDestroyItem'
EsoUI/Ingame/Inventory/InventorySlot.lua:1453: in function 'OnSelect'
EsoUI/Libraries/ZO_ContextMenus/ZO_ContextMenus.lua:412: in function 'ZO_Menu_ClickItem'
8371350907706105899:4: in function '(main chunk)'

Report here:
Error deleting items every few hours.
=(
Looking for addon causing a bug

Any addon showing a context-menu can causes it. But there is nothing wrong with the calling:
ClearMenu() AddMenuItem ... ShowMenu(), right?

How to reproduce:
Do in chat window:
1. /reloadui
2. /script ClearMenu() AddMenuItem("") ShowMenu() ClearMenu()
3. Go and use an item of your inventory using context-menu

unsecure code?!?

Try this:
1. /reloadui
2. go and open journal and right-click a quest to open a context-menu. In fact any build-in context-menu would be ok. You could also open the context-menu of the inventory.
3. /script ClearMenu() AddMenuItem("") ShowMenu() ClearMenu()
4. Go and use an item of your inventory using context-menu

now the same code is secure.

The critical call is AddMenuItem("")
Here is another example:
"secure" code adding a normal button below the context-menu
Lua Code:
  1. local good = WINDOW_MANAGER:CreateControlFromVirtual("GoodBoy", ZO_Menu, "ZO_DefaultButton")
  2. good:SetDimensions(320, 32)
  3. good:SetAnchor(TOPLEFT, nil, BOTTOMLEFT)
  4. good:SetText("Click me")

"unsecure" code adding a ZO_MenuItem control.
Lua Code:
  1. local bad = WINDOW_MANAGER:CreateControlFromVirtual("BadBoy", ZO_Menu, "ZO_MenuItem")
  2. bad:GetNamedChild("Name"):SetText("Click me")
  3. bad:SetAnchor(TOPLEFT, nil, BOTTOMLEFT)
  4. bad:SetHidden(false)
It depends on who uses the template ZO_MenuItem first?!?

Seems to be a game-in bug. Or AddMenuItem should not be public. What else should be used?

sirinsidiator 04/20/15 04:28 PM

We could create a library that does exactly the same thing as the ingame menu and use that instead :D

votan 04/21/15 01:47 AM

Quote:

Originally Posted by sirinsidiator (Post 20711)
We could create a library that does exactly the same thing as the ingame menu and use that instead :D

That is "Plan B". Because we need to use templates. And templates require XML. And XML can not be used from embedded libs.
Therefore I hoped ZOS would respond to this post. :)

A library needs cooperation from addon developers. It's worthless to write a lib, if everybody says "My code is working without". And basically that is true, because it's just the build-in code that does not work anymore :D

The main key to avoid this error is:
Never create an instance of ZO_MenuItem from addon code
=> Never use ZO_Menu.itemPool, so that build-in code does not re-use pooled controls created by addon code
=> Never use AddMenuItem

A library could introduce "AddCustomMenuItem", which uses its own pool using a template that mimics ZO_MenuItem.
(The ZO_Menu.checkBoxPool respectively)

But as far as I know, this must be a shared addon. Maybe a more experienced author finds a better solution?

QuadroTony 04/21/15 04:07 AM

Quote:

How to reproduce:
Do in chat window:
1. /reloadui
2. /script ClearMenu() AddMenuItem("") ShowMenu() ClearMenu()
3. Go and use an item of your inventory using context-menu
cant reproduce :)

votan 04/21/15 04:13 AM

Quote:

Originally Posted by QuadroTony (Post 20729)
cant reproduce :)

Really?!? Wow. Am I the only one!?!

Ayantir 04/21/15 04:17 AM

You just misswritten it.

it's :

/reloadui
/script ClearMenu()
/script AddMenuItem("")
/script ShowMenu()
/script ClearMenu()

Right click on an item > Delete : bug

;)

I can reproduce the problem too.

QuadroTony 04/21/15 04:25 AM

Quote:

Originally Posted by Ayantir (Post 20733)
You just misswritten it.

it's :

/reloadui
/script ClearMenu()
/script AddMenuItem("")
/script ShowMenu()
/script ClearMenu()

Right click on an item > Delete : bug

;)

I can reproduce the problem too.

yes!! i can reproduce it now

btw after this
/script ShowMenu()

i got a visual glitch

votan 04/21/15 04:30 AM

Quote:

Originally Posted by Ayantir (Post 20733)
You just misswritten it.

it's :

/reloadui
/script ClearMenu()
/script AddMenuItem("")
/script ShowMenu()
/script ClearMenu()

Right click on an item > Delete : bug

;)

I can reproduce the problem too.

Thanks Ayantir! I'm not nuts. (not fully :))
Separating commands by space in one line works for me. :confused: But ok.... that's better. Thanks again.

And thanks QuadroTony.
The glitch is nearly as expected. The context-menu should be empty. That's what ShowMenu does. But what is this blue thing?

QuadroTony 04/21/15 04:40 AM

when i mouseover this thing it become blue
like any context menu string when you mouseover it

Garkin 04/21/15 04:46 AM

Quote:

Originally Posted by QuadroTony (Post 20737)
when i mouseover this thing it become blue
like any context menu string when you mouseover it

It's not visual glitch, it works correctly. Script shows context menu with one item (one row), with no name ("", no text on the line) and when you point mouse over this item, it is highlighted.

votan 04/21/15 04:47 AM

Quote:

Originally Posted by QuadroTony (Post 20737)
when i mouseover this thing it become blue
like any context menu string when you mouseover it

:o of course..... it's time for lunch :D


All times are GMT -6. The time now is 06:07 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI