Reverse Factory

by Kryzeth

Reverse Factory machine will recycle (uncraft) nearly any item placed inside. Supports the recycling of most, if not all, modded items. Fully featured integration with Bobs Mods, Industrial Revolution, and Fantario (independently, not simultaneously)

Content
20 hours ago
0.13 - 2.0
61.7K
Manufacturing

g [Bug]: Crash occurs when disabling Automatic Ingredient Push

3 months ago

Bug:

The mod Reverse Factory (8.2.14) caused a non-recoverable error.
Please report this error to the mod author.

Error while running event reverse-factory::on_nth_tick(30)
LuaEntity API call when LuaEntity was invalid.
stack traceback:
    [C]: in function '__index'
    __reverse-factory__/control.lua:14: in function <__reverse-factory__/control.lua:3>

This occurred on a save that has been using the mod for years. This occurred when changing settings.

  1. Saved game.
  2. Exited save and loaded Mod Settings from main menu screen
  3. Disabled Automatic Ingredient Push (previously enabled)

Workaround:
1. Load broken game and open menu as soon as able.
2. Set the in-game settings to match the main menu settings
3. Save & exit
4. Load save.

Not sure why this works, but figured I'd give you as much info as possible.

3 months ago

It also appears that the settings no longer persist in game or after changing them in the main menu

3 months ago

Additional info:
The settings in the save file do not update when changed (which another post mentioned this is a base game issue).
I turned off "Use different mod settings per save" and the crash now occurs again.

3 months ago

I was able to add a single line to fix the issue:
Here's the updated checkinvis function:

function checkinvs()
    game.players[1].print("checkinvs")
    --Run through every currently active surface
    game.players[1].print("Number of global surfaces :"..#global.surfaces)
    for _, surface in pairs(global.surfaces) do
        --If at least one recycler in the list..
        if global[surface] then if next(global[surface]) then
            --Check through the entire list..
            for _, entity in pairs (global[surface]) do
                --Resets the timer if the recycler is not stopped by input
                local noResetTimer = true
                --Entity[1] is the actual recycler, Entity[2] is its timer
                --Then if the recycler has power..
                if entity[1] and entity[1].valid then
                    if entity[1].energy > 0 then
                        --Then if the recycler is not currently recycling..
                        if not entity[1].is_crafting() then
                            --Then if the output is currently empty..
                            if entity[1].get_output_inventory().is_empty() then
                                --Then if the input is currently not empty..
                                if entity[1].get_inventory(defines.inventory.assembling_machine_input).get_item_count() > 0 then
                                    --Decrement the timer, because the recycler is stopped with input
                                    entity[2] = countdown(entity[2])
                                    --Then if the timer has passed 0..
                                    if entity[2] < 0 then
                                        --Auto ingredient push and reset the timer if true
                                        pushIngredient(entity[1])
                                    --Do not reset the timer if the recycler is stopped by input
                                    else noResetTimer = false
                                    end
                                end
                            end
                        end
                    end
                end
                --Resets the timer if the recycler was not stopped,
                --or if the recycler has already pushed to output
                if noResetTimer then
                    entity[2]=settings.global["rf-timer"].value
                end
            end
        end end
    end
end
3 months ago

I added
if entity[1] and entity[1].valid then

2 months ago

Hmm... thanks for the fix, though when trying to perform the same steps to recreate the error, I got a slightly different error (global table wasn't being properly initialized). I wasn't actually able to recreate your error, but I included the fix you provided, since it shouldn't break anything anyways, and should prevent crashes related to invalid entities (though I'm still not entirely sure how that happened).

Now that I understand more about how control.lua code works, I was actually able to shuffle some code around to enable/disable the auto-ingredient push without having to save/reload. So if you disable or change the setting mid-game, it will be reflected in-game immediately, and if you change the settings from the main menu, those changes will be reflected immediately when you load up into the game. Hopefully no crashes either; I tested a few surface related mods and everything still seemed to work, though I haven't run any extensive testing.

Hopefully all mod setting related issues should be fixed as of v8.2.15

New response