Skip to content

Commit b8f8283

Browse files
authored
Merge pull request #162 from Courseplay/138-lua-error
Try / catch for possible broken Giants function ..
2 parents a77853f + 0066d34 commit b8f8283

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

scripts/ai/util/AIUtil.lua

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,12 @@ end
707707

708708
function AIUtil.getWidth(vehicle)
709709
if vehicle.getAIAgentSize then
710-
local width, length, lengthOffset, frontOffset, height = vehicle:getAIAgentSize()
710+
--- Due to invalid implement ai comfigurations this function call might break the save ...
711+
--- So we try it and except the callstack, as every good vehicle/implement should cause this function to fail ..
712+
local valid, width = CpUtil.try(vehicle.getAIAgentSize, vehicle)
713+
if not valid then
714+
return vehicle.size.width
715+
end
711716
return width
712717
else
713718
return vehicle.size.width
@@ -716,10 +721,15 @@ end
716721

717722
function AIUtil.getLength(vehicle)
718723
if vehicle.getAIAgentSize then
719-
vehicle:updateAIAgentAttachments()
720-
local width, length, lengthOffset, frontOffset, height = vehicle:getAIAgentSize()
721-
for _, attachment in ipairs(vehicle.spec_aiDrivable.attachments) do
722-
length = length + attachment.length
724+
--- Due to invalid implement ai comfigurations these function calls might break the save ...
725+
--- So we try it and except the callstack, as every good vehicle/implement should cause this function to fail ..
726+
local valid = CpUtil.try(vehicle.updateAIAgentAttachments, vehicle)
727+
if not valid then
728+
return vehicle.size.length
729+
end
730+
local valid, width, length, lengthOffset, frontOffset, height = CpUtil.try(vehicle.getAIAgentSize, vehicle)
731+
if not valid then
732+
return vehicle.size.length
723733
end
724734
return length
725735
else

0 commit comments

Comments
 (0)