From 17e4b088f1ce2f5890c309d500c8cd78e15d3fa3 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Mon, 20 Feb 2023 17:45:10 +0100 Subject: [PATCH] Fix crash when game starts tick_paused Check patch number in update_instance step to ensure the clusterio_api is properly initialized if the game started tick paused and no ticks to trigger the patch check have happened yet. --- packages/slave/modules/clusterio/impl.lua | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/slave/modules/clusterio/impl.lua b/packages/slave/modules/clusterio/impl.lua index 452a3a30..93175950 100644 --- a/packages/slave/modules/clusterio/impl.lua +++ b/packages/slave/modules/clusterio/impl.lua @@ -1,16 +1,18 @@ local api = require('modules/clusterio/api') -local impl = {} - -impl.events = {} -impl.events[defines.events.on_tick] = function() +local function check_patch() if global.clusterio_patch_number ~= clusterio_patch_number then global.clusterio_patch_number = clusterio_patch_number script.raise_event(api.events.on_server_startup, {}) end end +local impl = {} +impl.events = {} + +impl.events[defines.events.on_tick] = check_patch + impl.events[api.events.on_server_startup] = function() if not global.clusterio then global.clusterio = { @@ -47,6 +49,7 @@ end -- Internal API clusterio_private = {} function clusterio_private.update_instance(new_id, new_name) + check_patch() global.clusterio.instance_id = new_id global.clusterio.instance_name = new_name script.raise_event(api.events.on_instance_updated, {