From 322e163daa4a9f1b6314842fed162d79ebdc78fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ritzl?= Date: Sat, 29 Jul 2023 10:42:46 +0200 Subject: [PATCH 1/4] Set cowait flag --- monarch/monarch.lua | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/monarch/monarch.lua b/monarch/monarch.lua index 0e6fa64..22bbefe 100644 --- a/monarch/monarch.lua +++ b/monarch/monarch.lua @@ -7,6 +7,7 @@ local CONTEXT = hash("monarch_context") local PROXY_LOADED = hash("proxy_loaded") local PROXY_UNLOADED = hash("proxy_unloaded") local LAYOUT_CHANGED = hash("layout_changed") +local WAITFOR_COWAIT = hash("waitfor_cowait") local RELEASE_INPUT_FOCUS = hash("release_input_focus") local ACQUIRE_INPUT_FOCUS = hash("acquire_input_focus") @@ -82,10 +83,13 @@ local function assign(to, from) return to end -local function cowait(delay) +local function cowait(screen, delay) + log("cowait()", screen.id, delay) local co = coroutine.running() assert(co, "You must run this from within a coroutine") + screen.wait_for = WAITFOR_COWAIT timer.delay(delay, false, function() + screen.wait_for = nil assert(coroutine.resume(co)) end) coroutine.yield() @@ -411,8 +415,8 @@ local function unload(screen, force) -- we need to wait here in case the unloaded screen contained any screens -- if this is the case we need to let these sub-screens have their final() -- functions called so that they have time to call unregister() - cowait(0) - cowait(0) + cowait(screen, 0) + cowait(screen, 0) end @@ -518,8 +522,8 @@ local function focus_lost(screen, next_screen) -- unloaded this will happen before the focus_lost message reaches -- the focus_url -- we add a delay to ensure the message queue has time to be processed - cowait(0) - cowait(0) + cowait(screen, 0) + cowait(screen, 0) else log("focus_lost() no focus url - ignoring") end @@ -640,7 +644,7 @@ local function show_in(screen, previous_screen, reload, add_to_stack, wait_for_t return end -- wait one frame so that the init() of any script have time to run before starting transitions - cowait(0) + cowait(screen, 0) reset_timestep(screen) transition(screen, M.TRANSITION.SHOW_IN, { previous_screen = previous_screen and previous_screen.id }, wait_for_transition) screen.visible = true @@ -666,7 +670,7 @@ local function back_in(screen, previous_screen, wait_for_transition, cb) return end -- wait one frame so that the init() of any script have time to run before starting transitions - cowait(0) + cowait(screen, 0) reset_timestep(screen) if previous_screen and not previous_screen.popup then transition(screen, M.TRANSITION.BACK_IN, { previous_screen = previous_screen.id }, wait_for_transition) From dc11f1480a03a962ee18481270d41973fc8d4829 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ritzl?= Date: Sat, 29 Jul 2023 10:43:16 +0200 Subject: [PATCH 2/4] Set screen as unregistered --- monarch/monarch.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/monarch/monarch.lua b/monarch/monarch.lua index 22bbefe..0fe7b9c 100644 --- a/monarch/monarch.lua +++ b/monarch/monarch.lua @@ -327,6 +327,7 @@ function M.unregister(id) id = tohash(id) assert(screens[id], ("There is no screen registered with id %s"):format(tostring(id))) log("unregister()", id) + local screen = screens[id] screens[id] = nil -- remove screen from stack for i = #stack, 1, -1 do @@ -334,6 +335,10 @@ function M.unregister(id) table.remove(stack, i) end end + screen.unregistered = true + if screen.wait_for then + assert(coroutine.resume(screen.co)) + end end local function acquire_input(screen) @@ -442,6 +447,9 @@ local function preload(screen) screen.wait_for = PROXY_LOADED msg.post(screen.proxy, ASYNC_LOAD) coroutine.yield() + if screen.unregistered then + return false, "Screen was unregistered while loading" + end elseif screen.factory then log("preload() factory") if collectionfactory.get_status(screen.factory) == collectionfactory.STATUS_UNLOADED then @@ -449,6 +457,9 @@ local function preload(screen) assert(coroutine.resume(screen.co)) end) coroutine.yield() + if screen.unregistered then + return false, "Screen was unregistered while loading" + end end if collectionfactory.get_status(screen.factory) ~= collectionfactory.STATUS_LOADED then From 4ae72d136ea1c821564519da2871b4225c4fe79a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ritzl?= Date: Sat, 29 Jul 2023 11:07:08 +0200 Subject: [PATCH 3/4] Do not process screen which have been unregistered --- monarch/monarch.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/monarch/monarch.lua b/monarch/monarch.lua index ff96b07..a5c7735 100644 --- a/monarch/monarch.lua +++ b/monarch/monarch.lua @@ -390,6 +390,7 @@ local function change_context(screen) end local function unload(screen, force) + if screen.unregistered then return end if screen.proxy then log("unload() proxy", screen.id) if screen.auto_preload and not force then @@ -509,6 +510,7 @@ end local function transition(screen, message_id, message, wait) log("transition()", screen.id) + if screen.unregistered then return end if screen.transition_url then screen.wait_for = WAITFOR_TRANSITION_DONE msg.post(screen.transition_url, message_id, message) @@ -532,6 +534,7 @@ end local function focus_lost(screen, next_screen) log("focus_lost()", screen.id) + if screen.unregistered then return end if screen.focus_url then msg.post(screen.focus_url, M.FOCUS.LOST, { id = next_screen and next_screen.id }) -- if there's no transition on the screen losing focus and it gets From 6d316f1d22e7dbbc66beeac0f8f3e8f2c8867754 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ritzl?= Date: Sat, 29 Jul 2023 11:13:18 +0200 Subject: [PATCH 4/4] Java 17 --- .github/workflows/ci-workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-workflow.yml b/.github/workflows/ci-workflow.yml index 11d4542..b3ed4c9 100644 --- a/.github/workflows/ci-workflow.yml +++ b/.github/workflows/ci-workflow.yml @@ -10,7 +10,7 @@ jobs: - uses: actions/checkout@v1 - uses: actions/setup-java@v1 with: - java-version: '11' + java-version: '17' - name: Run.sh env: DEFOLD_USER: bjorn.ritzl@gmail.com