Wrap DEAD event handler in pcall as it sometimes fails (#3497)

This commit is contained in:
zhexu14 2025-04-06 22:43:52 +10:00 committed by GitHub
parent 5f66b6230f
commit 023c56700e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -176,6 +176,8 @@ local function onEvent(event)
end end
if event.id == world.event.S_EVENT_DEAD and event.initiator then if event.id == world.event.S_EVENT_DEAD and event.initiator then
get_initiator_name_success, initiator_name = pcall(event.initiator.getName, event.initiator)
if get_initiator_name_success then
dead_events[#dead_events + 1] = event.initiator.getName(event.initiator) dead_events[#dead_events + 1] = event.initiator.getName(event.initiator)
local position = event.initiator.getPosition(event.initiator) local position = event.initiator.getPosition(event.initiator)
local destruction = {} local destruction = {}
@ -187,6 +189,7 @@ local function onEvent(event)
destroyed_objects_positions[#destroyed_objects_positions + 1] = destruction destroyed_objects_positions[#destroyed_objects_positions + 1] = destruction
write_state() write_state()
end end
end
if event.id == world.event.S_EVENT_HIT then if event.id == world.event.S_EVENT_HIT then
target_category = event.target:getCategory() target_category = event.target:getCategory()