[boskid][2.0.28] scripting: LuaTransportLine.get_line_item_position() assumes transport line is straight

This subforum contains all the issues which we already resolved.
feyry
Manual Inserter
Manual Inserter
Posts: 3
Joined: Fri Apr 26, 2024 7:18 pm
Contact:

[boskid][2.0.28] scripting: LuaTransportLine.get_line_item_position() assumes transport line is straight

Post by feyry »

Screenshot demonstrating the bug
Screenshot demonstrating the bug
12-27-2024, 19-15-22.png (2.46 MiB) Viewed 534 times
The get_line_item_position function of LuaTransportLine is returning a MapPosition outside the LuaTransportLine, it appears to be assuming the line is straight (perhaps inheriting behavior from the LuaEntity the LuaTransportLine belongs to ?)

To replicate the bug, create a curved belt similar to the screenshot and then run the following lua snippet:
Or run the snippet after loading the attached scenario and (make sure time isn't paused!)

Code: Select all

local surface = game.player.surface
local entities = surface.find_entities_filtered{area = area, name = "underground-belt"}
for _, thing in pairs(entities) do
  i = 1
  --for i=1, thing.get_max_transport_line_index() do
  local tl = thing.get_transport_line(i)
  local pos = tl.get_line_item_position(tl.line_length)
  surface.print(i .. ": [" .. "gps=" .. pos.x .. "," .. pos.y .. "]")
  --end --lines
  break
end --belts
Attachments
get_line_item_position bug demo.zip
Scenario with a setup that will reproduce the bug
(1.39 MiB) Downloaded 11 times
User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 3362
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: [boskid][2.0.28] scripting: LuaTransportLine.get_line_item_position() assumes transport line is straight

Post by boskid »

Thanks for the report. Issue is now fixed for 2.0.29.

Issue was that LuaTransportLine::get_line_item_position was passing incorrect position value to the underlying entity when transport lines were merged. LuaTransportLine tries to hide how transport lines are merged between entities by providing only a perspective onto a section of transport line over a specific entity, however it was missing one addition that would convert provided position into a position along the entire transport line and so an underground belt saw an unreasonably small position value, subtracted its own position on the entire transport line and got a negative coordinate that was then put into position function causing an out of entity's bounds position to be given.
feyry
Manual Inserter
Manual Inserter
Posts: 3
Joined: Fri Apr 26, 2024 7:18 pm
Contact:

Re: [boskid][2.0.28] scripting: LuaTransportLine.get_line_item_position() assumes transport line is straight

Post by feyry »

Awesome!!! Thank you!
Post Reply

Return to “Resolved Problems and Bugs”