troelsbjerre / Bottleneck

Factorio mod that tell you which assemblers are starved of ingredients
Other
29 stars 21 forks source link

Missing sanity checks - instant deconstuction error #7

Closed Nexela closed 8 years ago

Nexela commented 8 years ago

Instant deconstruction mods can play havoc with bottleneck causing the entities and attached signals to become invalid.

Proposed changes:

control.lua line 125 if signal and signal.valid then

This one could probably be re-written a little bit better. control.lua line 144

function change_signal(data, signal_color)
    local entity = data.entity
    local signal = data.signal
    local name
    if signal and signal.valid then name=signal.name end
    if (not signal) or name ~= signal_color then
        if signal and signal.valid then
            signal.destroy()
        end
        if entity and entity.valid then data.signal = entity.surface.create_entity({ name = signal_color, position = data.position }) end
    end
end
troelsbjerre commented 8 years ago

There shouldn't as such be a problem with instant deconstruction mods, if the mod only deconstructs entities that the player can place. The signals are decorative, do not have a selection box, and cannot be picked up or directly placed by the player. The normal Deconstruction Planner does not interact with decorative entities, so why should an instant one do so? I'll include the line 125 change, since it might make Bottleneck play better with misbehaving mods.

As for the "change_signal" function, there is no reason to check "entity and entity.valid", since the function can only be reached if entity is already valid (assuming items cannot be built invalid).

Nexela commented 8 years ago

Wasn't sure on the entity part I just did a quick peek at your code. I was error-ing on 125 and the line with signal.name I didn't take into consideration that my version of the deconstruction planner is pretty aggressive it removes -all- entities and/or tiles. But thinking about it now it might be better if I add a few tick delay before looping through decoration entities after going through player place able entities..

troelsbjerre commented 8 years ago

Fixed in 0.3.2