Flamethrower turret #fluidbox == 2 but crashes on .get_filter(2)

Post Reply
Soul-Burn
Inserter
Inserter
Posts: 28
Joined: Sun Jan 31, 2021 9:07 pm
Contact:

Flamethrower turret #fluidbox == 2 but crashes on .get_filter(2)

Post by Soul-Burn »

The prototype has 1 fluid box, while in game 2 are visible when printed. However, .get_filter(2) crashes

While running this code from a mod I am developing:

Code: Select all

    local fb = entity.fluidbox
    for i = 1, #fb do
        log(entity.name .. " " .. #fb .. " " .. i)
        local filter = fb.get_filter(i)
        ...
The last line crashes with this log output:

Code: Select all

  24.984 Script @__fluid-connection-indicators__/control.lua:85: flamethrower-turret 2 1
  24.984 Script @__fluid-connection-indicators__/control.lua:85: flamethrower-turret 2 2
  24.993 Error MainLoop.cpp:1391: Exception at tick 1105: The mod Fluid Connection Indicators (0.1.2) caused a non-recoverable error.
Please report this error to the mod author.

Error while running event fluid-connection-indicators::on_built_entity (ID 6)
Passed index is out of range.
stack traceback:
    [C]: in function 'get_filter'
    __fluid-connection-indicators__/control.lua:86: in function 'update_entity'
    __fluid-connection-indicators__/control.lua:115: in function <__fluid-connection-indicators__/control.lua:109>
I was informed there is an edge case with .get_filter() with flamethrower turrets, and to report it here.

User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 2252
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: Flamethrower turret #fluidbox == 2 but crashes on .get_filter(2)

Post by boskid »

Ref 0.15.31: "Exposed internal buffer of fluid turret to Lua as its last fluidbox."

User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 2252
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: Flamethrower turret #fluidbox == 2 but crashes on .get_filter(2)

Post by boskid »

Thanks for the report. As mentioned in previous message, this is a side effect of a hack implemented in 0.15.31 which tries to expose internal buffer of fluid turret through a LuaFluidBox class. Issue is that internal buffer is not a FluidBox and a such does not support concept of a filter. Multiple methods were hiding those type differences by providing some dummy values however i decided to put a stop to this so in 2.0 the internal buffer of fluid turret will no longer be accessible through LuaFluidBox at all since it is not a fluid box. Same applies to fluid wagon's content. For this there will be a separate api implemented.

As for now you may need a workaround: if entity is of type `fluid-turret`, at index==2 there is no FluidBox so only fluid content read and write should be performed. I decided to not touch 1.1.x because it could quickly become a mod breaking change. Issue is fixed for 2.0.

Post Reply

Return to “Fixed for 2.0”