renoth / factorio-alien-module

A mod for factorio
MIT License
14 stars 16 forks source link

Crash when adding mod into existing game #92

Closed AndyScull closed 4 days ago

AndyScull commented 8 months ago

Hello, I just wanted to try the mod in my old base, got this error right after loading the game

The mod Alien Loot Economy (1.4.5) caused a non-recoverable error.
Please report this error to the mod author.

Error while running event alien-module::on_init()
LuaPlayer doesn't contain key forceName.
stack traceback:
    [C]: in function '__index'
    __alien-module__/control.lua:49: in function 'init_gui'
    __alien-module__/control.lua:6: in function <__alien-module__/control.lua:1>

To be sure, I disabled all mods, started a clear new game, saved and loaded it after enabling Alien Loot, the same error.

renoth commented 8 months ago

Can you try with the latest Version 1.4.6?

AndyScull commented 8 months ago

Yeah, tried, got similar error -

Error while running event alien-module::on_init()
__alien-module__/control.lua:48: attempt to perform arithmetic on field '?' (a nil value)
stack traceback:
    __alien-module__/control.lua:49: in function 'init_gui'
    __alien-module__/control.lua:6: in function <__alien-module__/control.lua:1>

To debug it a bit, I added a line of log(player.force.name) right before this line, got this:

  19.491 Script @__alien-module__/control.lua:48: player
  19.834 Error AppManagerStates.cpp:1659: The mod Alien Loot Economy (1.4.6) caused a non-recoverable error.
<the same error here>

I am not a pro programmer so just trying some things without luck. I think in on_init, verifyCountersForForce("player") should go before init_gui(), this got me to not crashing, and getting a base 'TEST' bar. Further, if I add update_gui() to init, it correctly shows 0 kills and does not crash. but if I wait 10s for next update_gui, it crashes, and looks like global.killcount was reinitialized during this time?

__alien-module__/control.lua:22: attempt to compare table with number
stack traceback:
    __alien-module__/control.lua:22: in function 'modulelevel'
    __alien-module__/control.lua:30: in function 'roundModuleLevel'
    __alien-module__/control.lua:97: in function 'update_gui'
AndyScull commented 8 months ago

OK so I kinda found out what was wrong. First, it really should be init_gui after fixing counters, this fixed first problem with crash right after load.

    verifyCountersForForce("player") -- initialize single player
    init_gui()
end)

Second problem, when after 10s the mod still crashed, was from migration\alien-module_1.4.0.lua. Seems like migration scripts run after main mod init, and this one breaks newly created global tables. Maybe they don't run at all when you start the new game, only when you load

vfinn commented 5 months ago

I posted a fix for this here: https://github.com/renoth/factorio-alien-module/issues/98

renoth commented 5 months ago

Please test with 1.4.10