From 6ba30647498fa500d3855ec6c1a78edf95d211f0 Mon Sep 17 00:00:00 2001 From: Pawel Date: Mon, 4 Mar 2024 16:06:56 +0100 Subject: [PATCH] Fixed an error that appears when trying to delete an instance that is already deleted. (#109) * Prevent deleting already removed instances. * Prehashed empty hash. * Use go.exists instead of pcall, when detecting non existing instances. --- monarch/monarch.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/monarch/monarch.lua b/monarch/monarch.lua index 26aa590..919dc2d 100644 --- a/monarch/monarch.lua +++ b/monarch/monarch.lua @@ -430,7 +430,9 @@ local function unload(screen, force) elseif screen.factory then log("unload() factory", screen.id) for id, instance in pairs(screen.factory_ids) do - go.delete(instance) + if go.exists(instance) then + go.delete(instance) + end end screen.factory_ids = nil if screen.auto_preload and not force then @@ -1374,8 +1376,10 @@ function M.on_post(id, fn_or_url) end end +local empty_hash = hash("") + local function url_to_key(url) - return (url.socket or hash("")) .. (url.path or hash("")) .. (url.fragment or hash("")) + return (url.socket or empty_hash) .. (url.path or empty_hash) .. (url.fragment or empty_hash) end