ShadowTheAge / yafc

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

[Loading error] Error with Eradicator's L.I.B.R.A.R.Y. #199

Open sproott opened 1 year ago

sproott commented 1 year ago

I'm using YAFC version 0.5.8 from FlatHub and Factorio version 1.1.76.

When loading YAFC with just Eradicator's L.I.B.R.A.R.Y., it crashes with the following error:

Require base/prototypes/equipment.lua
Require base/prototypes/legacy/legacy-entities.lua
Require base/prototypes/custom-inputs.lua
Require base/menu-simulations/menu-simulations.lua
Executing base/data-updates.lua
Executing eradicators-library/data-final-fixes.lua
Require eradicators-library/erlib/empty.lua
Require eradicators-library/erlib/shared.lua
Require 00-toggle-to-enable-dev-mode/empty.lua
Unhandled exception. System.Collections.Generic.KeyNotFoundException: The given key '00-toggle-to-enable-dev-mode' was not present in the dictionary.
   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   at YAFC.Parser.FactorioDataSource.ReadModFile(String modName, String path) in /app/yafc/YAFCparser/FactorioDataSource.cs:line 67
   at YAFC.Parser.LuaContext.Require(IntPtr lua) in /app/yafc/YAFCparser/LuaContext.cs:line 351
   at YAFC.Parser.LuaContext.lua_pcallk(IntPtr state, Int32 nargs, Int32 nresults, Int32 msgh, IntPtr ctx, IntPtr k)
   at YAFC.Parser.LuaContext.Exec(ReadOnlySpan`1 chunk, String mod, String name, Int32 argument) in /app/yafc/YAFCparser/LuaContext.cs:line 408
   at YAFC.Parser.LuaContext.Require(IntPtr lua) in /app/yafc/YAFCparser/LuaContext.cs:line 353
   at YAFC.Parser.LuaContext.lua_pcallk(IntPtr state, Int32 nargs, Int32 nresults, Int32 msgh, IntPtr ctx, IntPtr k)
   at YAFC.Parser.LuaContext.Exec(ReadOnlySpan`1 chunk, String mod, String name, Int32 argument) in /app/yafc/YAFCparser/LuaContext.cs:line 408
   at YAFC.Parser.LuaContext.DoModFiles(String[] modorder, String fileName, IProgress`1 progress) in /app/yafc/YAFCparser/LuaContext.cs:line 436
   at YAFC.Parser.FactorioDataSource.Parse(String factorioPath, String modPath, String projectPath, Boolean expensive, IProgress`1 progress, ErrorCollector errorCollector, String locale, Boolean renderIcons) in /app/yafc/YAFCparser/FactorioDataSource.cs:line 287
   at YAFC.WelcomeScreen.LoadProject() in /app/yafc/YAFC/Windows/WelcomeScreen.cs:line 302
Fatal error. Internal CLR error. (0x80131506)
   at YAFC.Parser.LuaContext.lua_pcallk(IntPtr, Int32, Int32, Int32, IntPtr, IntPtr)
   at YAFC.Parser.LuaContext.lua_pcallk(IntPtr, Int32, Int32, Int32, IntPtr, IntPtr)
   at YAFC.Parser.LuaContext.Exec(System.ReadOnlySpan`1<Byte>, System.String, System.String, Int32)
   at YAFC.Parser.LuaContext.Require(IntPtr)
   at YAFC.Parser.LuaContext.lua_pcallk(IntPtr, Int32, Int32, Int32, IntPtr, IntPtr)
   at YAFC.Parser.LuaContext.lua_pcallk(IntPtr, Int32, Int32, Int32, IntPtr, IntPtr)
   at YAFC.Parser.LuaContext.Exec(System.ReadOnlySpan`1<Byte>, System.String, System.String, Int32)
   at YAFC.Parser.LuaContext.DoModFiles(System.String[], System.String, System.IProgress`1<System.ValueTuple`2<System.String,System.String>>)
   at YAFC.Parser.FactorioDataSource.Parse(System.String, System.String, System.String, Boolean, System.IProgress`1<System.ValueTuple`2<System.String,System.String>>, YAFC.Model.ErrorCollector, System.String, Boolean)
   at YAFC.WelcomeScreen+<LoadProject>d__32.MoveNext()
... the rest of the stacktrace

I tried to investigate a bit myself, but I couldn't really make much out of this, just that the mod does some interesting stuff with running require on 00-toggle-to-enable-dev-mode, which seems to be a small utility mod that you can install by copying it into your mods folder (see this subdir). Nonetheless, it works in Factorio but crashes YAFC.

Here's a save file to sync mods.

DaleStan commented 1 year ago

I can't figure out what Eradicator's doing either. I believe I found an issue with YAFC's handling of pcall(require, ...), but that isn't the only problem here.

Until someone smarter can figure out how to fix it properly: (1) replace the two calls to does_file_exist in shared.lua with false, and (2) on line 346 of erlib/factorio/Stacktrace.lua, replace flag.IS_FACTORIO with false. I don't know if/how this will mess up anyone using erlib, though.

ShadowTheAge: I tried making FactorioDataSource.ReadModFile return null when it intercepted pcall(require, '__00-toggle-to-enable-dev-mode__/empty'), but I couldn't figure out how to get pcall to return false.