fix(client/interface): set openMenu to nil before triggering callbacks

Callbacks may open another menu, which then gets set to nil after
the callback has returned.
This commit is contained in:
Linden
2022-08-23 19:12:50 +10:00
parent f18071f7e1
commit 1ea4b16c8b

View File

@@ -55,11 +55,13 @@ local function resetFocus()
end end
function lib.hideMenu(onExit) function lib.hideMenu(onExit)
if onExit and openMenu.onClose then local menu = openMenu
openMenu.onClose() openMenu = nil
if onExit and menu.onClose then
menu.onClose()
end end
openMenu = nil
resetFocus() resetFocus()
SendNUIMessage({ SendNUIMessage({
action = 'closeMenu' action = 'closeMenu'
@@ -84,15 +86,17 @@ RegisterNUICallback('confirmSelected', function(data, cb)
data[2] += 1 -- scrollIndex data[2] += 1 -- scrollIndex
end end
if openMenu.options[data[1]].close ~= false then local menu = openMenu
openMenu = nil
if menu.options[data[1]].close ~= false then
resetFocus() resetFocus()
end end
if openMenu.cb then if menu.cb then
openMenu.cb(data[1], data[2], openMenu.options[data[1]].args) menu.cb(data[1], data[2], menu.options[data[1]].args)
end end
openMenu = nil
end) end)
RegisterNUICallback('changeIndex', function(data, cb) RegisterNUICallback('changeIndex', function(data, cb)
@@ -125,9 +129,10 @@ RegisterNUICallback('closeMenu', function(data, cb)
cb(1) cb(1)
resetFocus() resetFocus()
if openMenu.onClose then local menu = openMenu
openMenu.onClose()
end
openMenu = nil openMenu = nil
if menu.onClose then
menu.onClose()
end
end) end)