nihilistzsche / LtnManager

A GUI for managing your Logistic Train Network. A mod for Factorio.
https://mods.factorio.com/mod/LtnManager
MIT License
49 stars 13 forks source link

Crash on load with 0.3.1 & 0.3.0 #105

Closed dcbishop closed 3 years ago

dcbishop commented 3 years ago

Describe the Bug

Crash on load with 0.3.1. Thought it was related to the other one but now I'm guessing it's different. Not playing multiplayer. And haven't changed any locale settings from English (although I do note that there are 'unknown-keys' in the descriptions of some items (playing modded, Space Exploration + K2).

The mod LTN Manager [ALPHA] (0.3.1) caused a non-recoverable error.
Please report this error to the mod author.

Error while running event LtnManager::on_tick (ID 0)
__LtnManager__/scripts/util.lua:69: attempt to concatenate field 'delivering-to' (a nil value)
stack traceback:
    __LtnManager__/scripts/util.lua:69: in function 'get_status_string'
    __LtnManager__/scripts/ltn-data.lua:241: in function 'callback'
    __flib__/table.lua:196: in function <__flib__/table.lua:169>
    (...tail calls...)
    __LtnManager__/scripts/ltn-data.lua:506: in function 'iterate'
    __LtnManager__/control.lua:157: in function <__LtnManager__/control.lua:153>

Also a slightly different error from the 0.3.0 (I saw the above one under that version also).

The mod LTN Manager [ALPHA] (0.3.0) caused a non-recoverable error.
Please report this error to the mod author.

Error while running event LtnManager::on_tick (ID 0)
__LtnManager__/scripts/util.lua:80: attempt to concatenate field 'fetching-from' (a nil value)
stack traceback:
    __LtnManager__/scripts/util.lua:80: in function 'get_status_string'
    __LtnManager__/scripts/ltn-data.lua:241: in function 'callback'
    __flib__/table.lua:196: in function <__flib__/table.lua:169>
    (...tail calls...)
    __LtnManager__/scripts/ltn-data.lua:494: in function 'iterate'
    __LtnManager__/control.lua:157: in function <__LtnManager__/control.lua:153>

To Reproduce

Load the save...

Save file & Username

https://www.sendspace.com/file/g4j1qn Username: H3g3m0n

Log file

factorio-previous.log

raiguard commented 3 years ago

This is very strange, I am unable to reproduce it. Are you sure it happens every single time?

image

dcbishop commented 3 years ago

Yep keeps happening. Tried loading the game with out it and re-saving after a while in case it cleared something up but it's still happening. Reverted back to 0.2.7 and been playing for hours without issues. Tried 0.3.1 again and same error.

I tried logging the translations table with log(serpent.block(translations)) and it seemed to be blank {}, but I don't have much experience with Factorio modding/Lua.

raiguard commented 3 years ago

This is extremely strange, I'll keep trying and get back to you if I manage to reproduce it.

dcbishop commented 3 years ago

I tried totally a fresh blank install in case I screwed up the game files somehow, I also removed all mods other than LTN & Manager incase one of them was screwing things up but still getting the crash.

I also tried setting the locale to a different one (randomly chose Korean I think) without any effect.

Another slight variation on the error.

The mod LTN Manager [ALPHA] (0.3.2) caused a non-recoverable error.
Please report this error to the mod author.

Error while running event LtnManager::on_tick (ID 0)
__LtnManager__/scripts/ltn-data.lua:239: attempt to index field 'status' (a nil value)
stack traceback:
    __LtnManager__/scripts/ltn-data.lua:239: in function 'callback'
    __flib__/table.lua:196: in function <__flib__/table.lua:169>
    (...tail calls...)
    __LtnManager__/scripts/ltn-data.lua:504: in function 'iterate'
    __LtnManager__/control.lua:157: in function <__LtnManager__/control.lua:153>
cbtendo commented 3 years ago

I'm having the same issue crash on save load. strangely it didn't affect me in 0.3.0 or 0.3.1. Just after i updated it to 0.3.2. Here's the error log

The mod LTN Manager [ALPHA] (0.3.2) caused a non-recoverable error.
Please report this error to the mod author.

Error while running event LtnManager::on_tick (ID 0)
__LtnManager__/scripts/ltn-data.lua:287: attempt to compare two nil values
stack traceback:
    __LtnManager__/scripts/ltn-data.lua:287: in function <__LtnManager__/scripts/ltn-data.lua:286>
    [C]: in function 'sort'
    __LtnManager__/scripts/ltn-data.lua:286: in function 'callback'
    __flib__/table.lua:196: in function <__flib__/table.lua:169>
    (...tail calls...)
    __LtnManager__/scripts/ltn-data.lua:504: in function 'iterate'
    __LtnManager__/control.lua:157: in function <__LtnManager__/control.lua:153>

Here's the save file (link expires in 1 week)

https://we.tl/t-NPnR7VycE1

Forgot the log file https://we.tl/t-Qm9p3IfE8N

dcbishop commented 3 years ago

I added some debug logging to ltn-data.lua.

    function(data, key)
      print("LOGTEST")
      print("data:" .. serpent.block(data))
      print("key:" .. serpent.block(key))
      print("LOGTESTEND")
      local train = trains[key.train]
      train.status[key.player] = util.train.get_status_string(train, data.translations)
    end,

But I might have found 2 separate issues just confusing things. On my modded install, the data.translations field is blank.

On the same save on an fresh install without all the mods the translations field is correct but the train iterated on for the crash has basically no data fields.

Possibly modded trains being removed broke it? I was using the mod, "Multiple Unit Train Control" and @cbtendo log shows "Noxys Multidirectional Trains" which is something similar. Plus K2 has Nuclear locomotives. I tried removing the only multidirectional train I had but it didn't help (not sure if train information would be cached somewhere).

That would still leave the original issue though but it might point to a mod breaking translation somehow.

Debug printing with mods removed:

<snip a bunch of trains>
LOGTEST
data:{
  train = {
    capacity = 160,
    composition = "<L<CCCC",
    depot = "[virtual-signal=se-planet] Nauvis - [virtual-signal=ltn-depot] LTN - Depot",
    depot_priority = 0,
    fluid_capacity = 0,
    force = {
      __self = "userdata"
    },
    main_locomotive = {
      __self = "userdata"
    },
    network_id = 1,
    state = 7,
    status = {},
    surface = {
      __self = "userdata"
    },
    train = {
      __self = "userdata"
    }
  },
  translations = {
    ["delivering-to"] = "Delivering to",
    ["fetching-from"] = "Fetching from",
    ["loading-at"] = "Loading at",
    ["parked-at-depot"] = "Parked at depot",
    ["returning-to-depot"] = "Returning to depot",
    ["unloading-at"] = "Unloading at"
  }
}
key:{
  player = 1,
  train = 208
}
LOGTESTEND
LOGTEST
data:{
  train = {
    train = {
      __self = "userdata"
    }
  },
  translations = {
    ["delivering-to"] = "Delivering to",
    ["fetching-from"] = "Fetching from",
    ["loading-at"] = "Loading at",
    ["parked-at-depot"] = "Parked at depot",
    ["returning-to-depot"] = "Returning to depot",
    ["unloading-at"] = "Unloading at"
  }
}
key:{
  player = 1,
  train = 137
}
LOGTESTEND
  30.633 Error MainLoop.cpp:1207: Exception at tick 25538597: The mod LTN Manager [ALPHA] (0.3.2) caused a non-recoverable error.
Please report this error to the mod author.

Error while running event LtnManager::on_tick (ID 0)
__LtnManager__/scripts/ltn-data.lua:243: attempt to index field 'status' (a nil value)
stack traceback:
        __LtnManager__/scripts/ltn-data.lua:243: in function 'callback'
        __flib__/table.lua:196: in function <__flib__/table.lua:169>
        (...tail calls...)
        __LtnManager__/scripts/ltn-data.lua:508: in function 'iterate'
        __LtnManager__/control.lua:157: in function <__LtnManager__/control.lua:153>
  39.318 Quitting: user-quit.
  39.485 Goodbye

Debug printing on modded game:

LOGTEST
data:{
  train = {
    capacity = 0,
    composition = "<L<FFFF",
    depot = "[virtual-signal=se-planet] Nauvis - [virtual-signal=ltn-depot] LTN - Depot",
    depot_priority = 0,
    fluid_capacity = 100000,
    force = {
      __self = "userdata"
    },
    main_locomotive = {
      __self = "userdata"
    },
    network_id = 1,
    state = 7,
    status = {},
    surface = {
      __self = "userdata"
    },
    train = {
      __self = "userdata"
    }
  },
  translations = {}
}
key:{
  player = 1,
  train = 60
}
LOGTESTEND
LOGTEST
data:{
  train = {
    composition = "<L<CCCC",
    depot = "[virtual-signal=se-planet] Nauvis - [virtual-signal=ltn-depot] LTN - Depot",
    force = {
      __self = "userdata"
    },
    main_locomotive = {
      __self = "userdata"
    },
    network_id = 1,
    returning_to_depot = true,
    state = 7,
    status = {},
    train = {
      __self = "userdata"
    }
  },
  translations = {}
}
key:{
  player = 1,
  train = 70
}
LOGTESTEND
LOGTEST
data:{
  train = {
    composition = "<L<FFFF",
    depot = "[virtual-signal=se-planet] Nauvis - [virtual-signal=ltn-depot] LTN - Depot",
    force = {
      __self = "userdata"
    },
    from = "[virtual-signal=se-planet] Nauvis - [fluid=sulfuric-acid]⬈ Sulfuric Acid Pickup",
    from_id = 58542,
    main_locomotive = {
      __self = "userdata"
    },
    network_id = 1,
    pickupDone = true,
    shipment = {
      ["fluid,sulfuric-acid"] = 12540
    },
    started = 25535682,
    state = 0,
    status = {},
    to = "[virtual-signal=se-planet] Nauvis - [fluid=sulfuric-acid]⬊ Sulfuric Acid Dropoff Uranium Mine #2",
    to_id = 952038,
    train = {
      __self = "userdata"
    }
  },
  translations = {}
}
key:{
  player = 1,
  train = 89
}
LOGTESTEND
  75.012 Error MainLoop.cpp:1207: Exception at tick 25538485: The mod LTN Manager [ALPHA] (0.3.2) caused a non-recoverable error.
Please report this error to the mod author.

Error while running event LtnManager::on_tick (ID 0)
__LtnManager__/scripts/util.lua:69: attempt to concatenate field 'delivering-to' (a nil value)
stack traceback:
    __LtnManager__/scripts/util.lua:69: in function 'get_status_string'
    __LtnManager__/scripts/ltn-data.lua:243: in function 'callback'
    __flib__/table.lua:196: in function <__flib__/table.lua:169>
    (...tail calls...)
    __LtnManager__/scripts/ltn-data.lua:508: in function 'iterate'
    __LtnManager__/control.lua:157: in function <__LtnManager__/control.lua:153>
raiguard commented 3 years ago

I have still been completely unable to reproduce this issue on any of the save files I've been sent, and I still have no idea how this could be happening.

@dcbishop Thanks for your efforts, but your logging doesn't really help much. I already know that the translations are empty, the problem is I don't know why they are empty.

Could you replace your on_configuration_changed event code (in control.lua) with this, then send me the log output?

event.on_configuration_changed(function(e)
  if migration.on_config_changed(e, migrations) then
    -- migrate flib modules
    gui.check_filter_validity()
    translation.init()
    -- update translation data
    global_data.build_translations()
    -- ! DEBUGGING
    log("before ltn-data reset: \n"..serpent.block(global.flags))
    -- reset LTN data
    ltn_data.init()
    -- ! DEBUGGING
    log("after ltn-data reset: \n"..serpent.block(global.flags))
    -- refresh all player information
    for i, player in pairs(game.players) do
      -- close open GUIs
      local player_table = global.players[i]
      if player_table.gui.main then
        main_gui.close(player, player_table)
        main_gui.destroy(player, player_table)
      end
      -- ! DEBUGGING
      log("["..i.."] before reset: \n"..serpent.block(player_table.flags))
      -- refresh data
      player_data.refresh(player, player_table)
      -- ! DEBUGGING
      log("["..i.."] before reset: \n"..serpent.block(player_table.flags))
    end
  end
end)
dcbishop commented 3 years ago
 100.879 Script @__aai-programmable-structures__/control.lua:1713: AAI: checking 'errors'
 100.967 Script @__LogisticTrainNetwork__/script/init.lua:338: [LTN] LogisticTrainNetwork 1.14.5 configuration updated.
 101.131 Script @__LtnManager__/control.lua:80: {
  can_open_gui = false,
  gui_open = false,
  search_open = false,
  toggling_search = false,
  translate_on_join = false,
  translations_finished = true
}
 101.132 Script @__LtnManager__/control.lua:84: {
  can_open_gui = false,
  gui_open = false,
  search_open = false,
  toggling_search = false,
  translate_on_join = false,
  translations_finished = false
}
 101.288 Script @__space-exploration__/scripts/zone.lua:1887: Zone.zone_fix_all_tiles: planet Nauvis is_land 0 tiles changed surface_index 1 surface_name nauvis
 101.305 Script @__space-exploration__/scripts/zone.lua:1859: Zone.zone_fix_all_tiles: orbit Nauvis Orbit is_space 0 tiles changed surface_index 3 surface_name Nauvis Orbit
 101.314 Script @__space-exploration__/scripts/zone.lua:1887: Zone.zone_fix_all_tiles: moon Dolos is_land 0 tiles changed surface_index 4 surface_name Dolos
 101.327 Script @__space-exploration__/scripts/zone.lua:1887: Zone.zone_fix_all_tiles: moon Frost is_land 0 tiles changed surface_index 5 surface_name Frost
 102.981 Error MainLoop.cpp:1207: Exception at tick 25533141: The mod LTN Manager [ALPHA] (0.3.2) caused a non-recoverable error.
Please report this error to the mod author.

Error while running event LtnManager::on_tick (ID 0)
__LtnManager__/scripts/util.lua:80: attempt to concatenate field 'fetching-from' (a nil value)
stack traceback:
    __LtnManager__/scripts/util.lua:80: in function 'get_status_string'
    __LtnManager__/scripts/ltn-data.lua:239: in function 'callback'
    __flib__/table.lua:196: in function <__flib__/table.lua:169>
    (...tail calls...)
    __LtnManager__/scripts/ltn-data.lua:504: in function 'iterate'
    __LtnManager__/control.lua:161: in function <__LtnManager__/control.lua:157>
raiguard commented 3 years ago

Good news: I finally managed to reproduce it! Turns out that it was a problem with the custom next() function that would determine which player and train to generate status strings for. This has been fixed for the next release.

Thank you to all who reported the issue!