From 6b48551d59818b385200221f0a42afea0a3545d5 Mon Sep 17 00:00:00 2001 From: Eltrac Date: Wed, 12 Mar 2025 17:55:00 +0800 Subject: fix: game crash when creating new body during world update use a body lifecycle manager to create after world update is done --- main.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'main.lua') diff --git a/main.lua b/main.lua index a602cac..4076521 100644 --- a/main.lua +++ b/main.lua @@ -1,10 +1,9 @@ require "config" require "utils.utils" - require "render.sprite" require "render.speaker" - local map = require "logic.map" +local bodyLifeCycleManager = require "utils.bodyLifecycleManager" local controller = require "logic.controller" local translator = require "i18n.translator" @@ -21,6 +20,8 @@ function love.load() -- initialize game state initGame() + -- body life cycle manager + G.BodyLifeCycleManager = bodyLifeCycleManager.new() -- set world callbacks G.world:setCallbacks(onContact) @@ -33,7 +34,7 @@ end function love.update(dt) -- game state updates - local gameStates = { G.world, G.currentRoom, G.player } + local gameStates = { G.world, G.currentRoom, G.player, G.BodyLifeCycleManager } for _, state in ipairs(gameStates) do state:update(dt) end -- cgit v1.2.3