shpaass / yafc-ce

Powerful Factorio calculator/analyser that works with mods
GNU General Public License v3.0
51 stars 17 forks source link

crash: mods: Deadlock-SE-bridge + deadlock-beltboxes-loaders + space-exploration #105

Closed winex closed 1 month ago

winex commented 4 months ago
Log mods once: {
  ["Deadlock-SE-bridge"] = "0.6.6",
  ["aai-containers"] = "0.2.11",
  ["aai-industry"] = "0.5.22",
  ["aai-signal-transmission"] = "0.4.9",
  ["alien-biomes"] = "0.6.8",
  base = "1.1.107",
  ["deadlock-beltboxes-loaders"] = "2.4.2",
  informatron = "0.3.4",
  jetpack = "0.3.14",
  robot_attrition = "0.5.15",
  ["shield-projector"] = "0.1.6",
  simhelper = "1.1.6",
  ["space-exploration"] = "0.6.128",
  ["space-exploration-graphics"] = "0.6.17",
  ["space-exploration-graphics-2"] = "0.6.1",
  ["space-exploration-graphics-3"] = "0.6.2",
  ["space-exploration-graphics-4"] = "0.6.3",
  ["space-exploration-graphics-5"] = "0.6.1",
  ["space-exploration-menu-simulations"] = "0.6.9",
  ["space-exploration-postprocess"] = "0.6.28"
}
All mods found! Loading order: core, base, simhelper, aai-containers, aai-signal-transmission,
alien-biomes, deadlock-beltboxes-loaders, informatron, jetpack, robot_attrition, shield-projector,
space-exploration-graphics, space-exploration-graphics-2, space-exploration-graphics-3,
space-exploration-graphics-4, space-exploration-graphics-5, space-exploration-menu-simulations,
aai-industry, space-exploration, Deadlock-SE-bridge, space-exploration-postprocess
Mod settings parsed
yafc 0.6.3.0

last messages:

...
Executing Deadlock-SE-bridge/data-final-fixes.lua
Require space-exploration/data_util.lua
Require space-exploration/scripts/log.lua
Require space-exploration/shared_util.lua
Require Deadlock-SE-bridge/prototypes/deadlock.lua
Require Deadlock-SE-bridge/prototypes/colors.lua
Require deadlock-beltboxes-loaders/prototypes/shared.lua
Require deadlock-beltboxes-loaders/prototypes/create_loader.lua
Require deadlock-beltboxes-loaders/prototypes/shared.lua
Unhandled exception. YAFC.Parser.LuaException: (Deadlock-SE-bridge, prototypes/deadlock.lua):199: attempt to call field 'create_loader' (a nil value)
stack traceback:
[C]: in function 'create_loader'
(Deadlock-SE-bridge, prototypes/deadlock.lua):199: in main chunk
[C]: in function 'require'
(Deadlock-SE-bridge, data-final-fixes.lua):2: in main chunk
   at YAFC.Parser.LuaContext.Exec(ReadOnlySpan`1 chunk, String mod, String name, Int32 argument) in /home/winex/projects/factorio/yafc-ce/YAFCparser/LuaContext.cs:line 409
   at YAFC.Parser.LuaContext.Require(IntPtr lua) in /home/winex/projects/factorio/yafc-ce/YAFCparser/LuaContext.cs:line 353
Aborted (core dumped)

global variable deadlock_stacking:

$  grep -Rn --include="*.lua" -B3 -A3 -i 'deadlock_stacking' .
--
./Deadlock-SE-bridge_0.6.6/prototypes/deadlock.lua-85---Add beltbox tier
./Deadlock-SE-bridge_0.6.6/prototypes/deadlock.lua:86:if deadlock_stacking then
./Deadlock-SE-bridge_0.6.6/prototypes/deadlock.lua-87-  local DBL = require("__deadlock-beltboxes-loaders__/prototypes/shared")
./Deadlock-SE-bridge_0.6.6/prototypes/deadlock.lua-88-  require("__deadlock-beltboxes-loaders__/prototypes/create_loader")
./Deadlock-SE-bridge_0.6.6/prototypes/deadlock.lua-89-
--
./Deadlock-SE-bridge_0.6.6/prototypes/stacking.lua:94:      if deadlock_stacking and settings.startup["deadlock-enable-beltboxes"].value == true then
--
./deadlock-beltboxes-loaders_2.4.2/prototypes/public.lua-299--- tables for legacy interfaces from early 0.16 versions
./deadlock-beltboxes-loaders_2.4.2/prototypes/public.lua-300-deadlock_loaders = {}
./deadlock-beltboxes-loaders_2.4.2/prototypes/public.lua:301:deadlock_stacking = {}
--

they're internally adding to previously required tables, will this work the same way in YAFC?:

  local DBL = require("__deadlock-beltboxes-loaders__/prototypes/shared")
  require("__deadlock-beltboxes-loaders__/prototypes/create_loader")

-- but in prototypes/create_loader.lua:
function DBL.create_loader(tier_table)
    --...
end

"static" function to global DBL, while required is local - this looks weird to me...

...maybe they're totally wrong, but a crash must not happen!

shihan42 commented 4 months ago

That is indeed a strange thing. If I find the time, I might be looking into it. But no promises, RL is hard right now.

DaleStan commented 3 months ago

The critical lines are these two in Deadlock-SE-bridge/prototypes/deadlock.lua:

    local DBL = require("__deadlock-beltboxes-loaders__/prototypes/shared")
    require("__deadlock-beltboxes-loaders__/prototypes/create_loader")

In Factorio, the second require adds a create_loader value to DBL, while in YAFC the second require does nothing. The first line of create_loader.lua is local DBL = require("prototypes.shared"), and shared.lua starts with local DBL = {} and ends with return DBL.

My theory is that YAFC sees the local declaration twice and creates two different tables, while Factorio creates only one table.

If I make these two changes, the mods load in both YAFC and Factorio: ```diff diff --git a/Deadlock-SE-bridge_0.6.6/prototypes/deadlock.lua b/Deadlock-SE-bridge_0.6.6/prototypes/deadlock.lua index 0fe598b..100ffa7 100644 --- a/Deadlock-SE-bridge_0.6.6/prototypes/deadlock.lua +++ b/Deadlock-SE-bridge_0.6.6/prototypes/deadlock.lua @@ -84,8 +84,7 @@ --BELTBOX --Add beltbox tier if deadlock_stacking then - local DBL = require("__deadlock-beltboxes-loaders__/prototypes/shared") - require("__deadlock-beltboxes-loaders__/prototypes/create_loader") + local DBL = require("__deadlock-beltboxes-loaders__/prototypes/create_loader") remove_tech_pack ( data.raw.technology["deadlock-stacking-3"], { "production-science-pack" } ) diff --git a/deadlock-beltboxes-loaders_2.4.2/prototypes/create_loader.lua b/deadlock-beltboxes-loaders_2.4.2/prototypes/create_loader.lua index 08bd05d..e771123 100644 --- a/deadlock-beltboxes-loaders_2.4.2/prototypes/create_loader.lua +++ b/deadlock-beltboxes-loaders_2.4.2/prototypes/create_loader.lua @@ -277,3 +277,5 @@ ) end end + +return DBL ```

I don't know where to go from here, but hopefully someone else will be able to take this further.