Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(es_extended/callback): correctly dispose of function references #1494

Merged
merged 4 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion [core]/cron/fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ game 'gta5'
author 'ESX-Framework'
description 'Allows resources to Run tasks at specific intervals.'
lua54 'yes'
version '1.11.2'
version '1.11.3'

server_script 'server/main.lua'
1 change: 0 additions & 1 deletion [core]/es_extended/client/modules/adjustments.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ end
function Adjustments:DisableAimAssist()
if Config.DisableAimAssist then
SetPlayerTargetingMode(3)
SetPlayerLockonRangeOverride(ESX.playerId, 0.0)
end
end

Expand Down
22 changes: 18 additions & 4 deletions [core]/es_extended/client/modules/callback.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ function Callbacks:ServerRecieve(requestId, invoker, ...)
end
end

function Callbacks:Register(name, cb)
self.storage[name] = cb
function Callbacks:Register(name, resource, cb)
self.storage[name] = {
resource = resource,
cb = cb
}
end

function Callbacks:ClientRecieve(eventName, requestId, invoker, ...)
Expand All @@ -60,7 +63,7 @@ function Callbacks:ClientRecieve(eventName, requestId, invoker, ...)
local returnCb = function(...)
TriggerServerEvent("esx:clientCallback", requestId, invoker, ...)
end
local callback = self.storage[eventName]
local callback = self.storage[eventName].cb

self:Execute(callback, requestId, returnCb, ...)
end
Expand Down Expand Up @@ -106,9 +109,20 @@ end)
---@param callback function
---@return nil
ESX.RegisterClientCallback = function(eventName, callback)
Callbacks:Register(eventName, callback)
local invokingResource = GetInvokingResource()
local invoker = (invokingResource and invokingResource ~= "Unknown") and invokingResource or "es_extended"

Callbacks:Register(eventName, invoker, callback)
end

ESX.SecureNetEvent("esx:triggerClientCallback", function(...)
Callbacks:ClientRecieve(...)
end)

AddEventHandler("onResourceStop", function(resource)
for k, v in pairs(Callbacks.storage) do
if v.resource == resource then
Callbacks.storage[k] = nil
end
end
end)
2 changes: 1 addition & 1 deletion [core]/es_extended/fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ fx_version 'cerulean'
game 'gta5'
description 'The Core resource that provides the functionalities for all other resources.'
lua54 'yes'
version '1.11.2'
version '1.11.3'

shared_scripts {
'locale.lua',
Expand Down
23 changes: 18 additions & 5 deletions [core]/es_extended/server/modules/callback.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ Callbacks.requests = {}
Callbacks.storage = {}
Callbacks.id = 0

function Callbacks:Register(name, cb)
self.storage[name] = cb
function Callbacks:Register(name, resource, cb)
self.storage[name] = {
resource = resource,
cb = cb
}
end

function Callbacks:Execute(cb, ...)
Expand Down Expand Up @@ -39,7 +42,7 @@ function Callbacks:ServerRecieve(player, event, requestId, invoker, ...)
local returnCb = function(...)
TriggerClientEvent("esx:serverCallback", player, requestId, invoker, ...)
end
local callback = self.storage[event]
local callback = self.storage[event].cb

self:Execute(callback, player, returnCb, ...)
end
Expand Down Expand Up @@ -73,14 +76,24 @@ end)
---@param ... any
function ESX.TriggerClientCallback(player, eventName, callback, ...)
local invokingResource = GetInvokingResource()
local invoker = (invokingResource and invokingResource ~= "unknown") and invokingResource or "es_extended"
local invoker = (invokingResource and invokingResource ~= "Unknown") and invokingResource or "es_extended"

Callbacks:Trigger(player, eventName, callback, invoker, ...)
end

---@param eventName string
---@param callback function
ESX.RegisterServerCallback = function(eventName, callback)
Callbacks:Register(eventName, callback)
local invokingResource = GetInvokingResource()
local invoker = (invokingResource and invokingResource ~= "Unknown") and invokingResource or "es_extended"

Callbacks:Register(eventName, invoker, callback)
end

AddEventHandler("onResourceStop", function(resource)
for k, v in pairs(Callbacks.storage) do
if v.resource == resource then
Callbacks.storage[k] = nil
end
end
end)
2 changes: 1 addition & 1 deletion [core]/esx_chat_theme/fxmanifest.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version '1.11.2'
version '1.11.3'
author 'ESX-Framework'
description 'A ESX Stylised theme for the chat resource.'

Expand Down
2 changes: 1 addition & 1 deletion [core]/esx_context/fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ game 'gta5'
author 'ESX-Framework & Brayden'
description 'A simplistic context menu for ESX.'
lua54 'yes'
version '1.11.2'
version '1.11.3'

ui_page 'index.html'

Expand Down
2 changes: 1 addition & 1 deletion [core]/esx_identity/fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ fx_version 'adamant'
game 'gta5'
description 'Allows the player to Pick their characters: Name, Gender, Height and Date-of-birth.'
lua54 'yes'
version '1.11.2'
version '1.11.3'

shared_scripts {
'@es_extended/imports.lua',
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion [core]/esx_loadingscreen/fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ game 'common'
fx_version 'cerulean'
author 'ESX-Framework'
description 'Allows resources to Run tasks at specific intervals.'
version '1.11.2'
version '1.11.3'
lua54 'yes'

loadscreen 'index.html'
Expand Down
2 changes: 1 addition & 1 deletion [core]/esx_menu_default/fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ fx_version 'adamant'
game 'gta5'
description 'A basic menu system for ESX Legacy.'
lua54 'yes'
version '1.11.2'
version '1.11.3'

client_scripts { '@es_extended/imports.lua', 'client/main.lua' }

Expand Down
2 changes: 1 addition & 1 deletion [core]/esx_menu_dialog/fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ fx_version 'adamant'
game 'gta5'
description 'A basic input dialog for ESX Legacy.'
lua54 'yes'
version '1.11.2'
version '1.11.3'

client_scripts {
'@es_extended/imports.lua',
Expand Down
2 changes: 1 addition & 1 deletion [core]/esx_menu_list/fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ fx_version 'adamant'
game 'gta5'
description 'A basic table-based menu system for ESX Legacy.'
lua54 'yes'
version '1.11.2'
version '1.11.3'


client_scripts {
Expand Down
2 changes: 1 addition & 1 deletion [core]/esx_multicharacter/fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ fx_version 'cerulean'
game 'gta5'
author 'ESX-Framework - Linden - KASH'
description 'Allows players to have multiple characters on the same account.'
version '1.11.2'
version '1.11.3'
lua54 'yes'

dependencies { 'es_extended', 'esx_context', 'esx_identity', 'esx_skin' }
Expand Down
2 changes: 1 addition & 1 deletion [core]/esx_notify/fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ fx_version 'adamant'

lua54 'yes'
game 'gta5'
version '1.11.2'
version '1.11.3'
author 'ESX-Framework'
description 'A beautiful and simple NUI notification system for ESX'

Expand Down
2 changes: 1 addition & 1 deletion [core]/esx_progressbar/fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ fx_version 'adamant'
game 'gta5'
author 'ESX-Framework'
description 'A beautiful and simple NUI progress bar for ESX'
version '1.11.2'
version '1.11.3'
lua54 'yes'

client_scripts { 'Progress.lua' }
Expand Down
2 changes: 1 addition & 1 deletion [core]/esx_skin/fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ fx_version 'adamant'

game 'gta5'
description 'Allows players to customise their character\'s appearance'
version '1.11.2'
version '1.11.3'
lua54 'yes'

shared_scripts {
Expand Down
2 changes: 1 addition & 1 deletion [core]/esx_textui/fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ fx_version 'adamant'
game 'gta5'
author 'ESX-Framework'
description 'A beautiful and simple Persistent Notification system for ESX.'
version '1.11.2'
version '1.11.3'
lua54 'yes'

client_scripts { 'TextUI.lua' }
Expand Down
2 changes: 1 addition & 1 deletion [core]/skinchanger/fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ fx_version 'adamant'

game 'gta5'
description 'Saves/loads character appearances for ESX Legacy.'
version '1.11.2'
version '1.11.3'
lua54 'yes'

client_scripts {
Expand Down
Loading