Forcefully unload packages on VMF reload

This commit is contained in:
Lucas Schwiderski 2018-12-11 16:06:53 +01:00
parent e9502a1add
commit 115dd5eddc
2 changed files with 27 additions and 0 deletions

View file

@ -156,3 +156,29 @@ function vmf.update_package_manager()
end end
end end
end end
-- Forcefully unloads all mods and cleans the queue.
function vmf.unload_all_resource_packages()
for mod, packages in pairs(_loaded_packages) do
for package_name in pairs(packages) do
mod:warning(
"Force-unloading package '%s'. Please make sure to properly release packages when the mod is unloaded",
package_name
)
mod:unload_package(package_name)
end
end
_queued_packages = {}
if _loading_package then
_loading_package.mod:warning(
"Still loading package '%s'. Memory leaks may occur when unloading while a package is loading.",
_loading_package.package_name
)
_loading_package.callback = function(package_name)
_loading_package.mod:unload_package(package_name)
end
end
end

View file

@ -92,6 +92,7 @@ function vmf_mod_object:on_reload()
if VT1 then vmf.reset_map_view() end if VT1 then vmf.reset_map_view() end
vmf.mods_unload_event(false) vmf.mods_unload_event(false)
vmf.remove_custom_views() vmf.remove_custom_views()
vmf.unload_all_resource_packages()
vmf.hooks_unload() vmf.hooks_unload()
vmf.reset_guis() vmf.reset_guis()
end end