Auto Deconstruct

by mindmix

This mod marks drills that have no more resources to mine for deconstruction.

a month ago
0.13 - 1.1
695178

b Internal error if player is in map editor

1 year, 10 months ago
(updated 1 year, 10 months ago)

When I enter into the map editor, I periodically get error messages that look like this:

[autodeconstruct|on_cancelled_deconstruction]: Error: LuaEntity API call when LuaEntity was invalid
    __AutoDeconstruct__/autodeconstruct.lua:38: in function 'find_target'

I walked through the code to see what was happening, and the root cause appears to be the call to drill.order_deconstruction on line 200 of autodeconstruct.lua. Normally, that just marks the drill for deconstruction, but when drill.last_user is a player in the map editor (with instant deconstruction enabled), order_deconstruction actually instantly deletes the drill! This causes drill.valid to become false, so when find_target(drill) evaluates entity.drop_target, an error is raised.

There are two possible solutions here. The most obvious one is to simply call find_target prior to the call to drill.order_deconstruction, which would ensure the drill entity is still valid. However, that seems sketchy to me—when I’m in the editor, I don’t really want AutoDeconstruct to delete my mining drills.

I think a better solution is to just pass nil for the second argument of order_deconstruction (or omit it entirely). The docs note that the second argument is optional, and as far as I can tell, everything works just fine if you don’t provide it. In that case, the instant deconstruction behavior of the map editor doesn’t kick in, and the drill is actually marked for deconstruction, not deleted.

New response