Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.2.0] server crash when run with Prefab Counter 1.0.1 #12

Closed
gyroplast opened this issue Oct 6, 2021 · 1 comment · Fixed by #13
Closed

[1.2.0] server crash when run with Prefab Counter 1.0.1 #12

gyroplast opened this issue Oct 6, 2021 · 1 comment · Fixed by #13
Assignees
Labels
bug Something isn't working

Comments

@gyroplast
Copy link
Owner

When this mod and the Prefab Counter mod up to version 1.0.1 are both enabled, the server will crash:

[00:00:03]: Mod: mod-dont-starve-prefab-counter (Prefab Counter) [INFO ] starting       
[00:00:03]: Mod: mod-dont-starve-prefab-counter (Prefab Counter) [INFO ] CFG: log level set to INFO     
[00:00:03]: Mod: mod-dont-starve-prefab-counter (Prefab Counter) [INFO ] finished initialization        
[00:00:03]: Mod: mod-dont-starve-chat-announcements (Chat Announcements)        Loading modworldgenmain.lua     
[00:00:03]: Mod: mod-dont-starve-chat-announcements (Chat Announcements)          Mod had no modworldgenmain.lua. Skipping.     
[00:00:03]: Mod: mod-dont-starve-chat-announcements (Chat Announcements)        Loading modmain.lua     
[00:00:03]: Mod: mod-dont-starve-prefab-counter (Prefab Counter) [INFO ] starting initialization        
[00:00:03]: Mod: mod-dont-starve-prefab-counter (Prefab Counter) [INFO ] initializing DiscordClient     
[00:00:03]: SimLuaProxy::QueryServer()
[00:00:03]: Mod: mod-dont-starve-prefab-counter (Prefab Counter) [INFO ] installing monster death announcement handlers 
[00:00:03]: MOD ERROR: mod-dont-starve-chat-announcements (Chat Announcements): Mod: mod-dont-starve-chat-announcements (Chat Announcements)    
[00:00:03]: Event data unavailable: lavaarena_event_server/lavaarena_achievement_quest_defs
[00:00:03]: [string "../mods/mod-dont-starve-chat-announcements/..."]:281: bad argument #1 to 'pairs' (table expected, got nil)
LUA ERROR stack traceback:
        =[C] in function 'pairs'
        ../mods/mod-dont-starve-chat-announcements/modmain.lua(281,1) in function 'main'
        ../mods/mod-dont-starve-chat-announcements/modmain.lua(323,1) in main chunk
        =[C] in function 'xpcall'
        scripts/util.lua(754,1) in function 'RunInEnvironment'
        scripts/mods.lua(558,1) in function 'InitializeModMain'
        scripts/mods.lua(532,1) in function 'LoadMods'
        scripts/main.lua(343,1) in function 'ModSafeStartup'
        scripts/main.lua(449,1) in function 'callback'
        scripts/modindex.lua(103,1) in function 'BeginStartupSequence'
        scripts/main.lua(448,1) in function 'callback'
        scripts/modindex.lua(735,1)
        =[C] in function 'GetPersistentString'
        scripts/modindex.lua(709,1) in function 'Load'
        scripts/main.lua(447,1) in main chunk

The affected mod is the Chat Announcements mod here, as visible in the incorrect modname in the log entries, which have been overwritten with Prefab Counter data, as well as the bad argument #1 to 'pairs' error, which refers to an externally defined constant table, which should never be nil.

Running either mod alone does not cause any issue.

@gyroplast gyroplast added the bug Something isn't working label Oct 6, 2021
@gyroplast gyroplast self-assigned this Oct 6, 2021
@gyroplast
Copy link
Owner Author

The root cause was manipulation of the global package path for the require() calls, combined with using identical names for the const, util, and logging modules in both mods. The later mod, Chat Announcements, will encounter a package.path manipulated to look up modules in the Prefab Counter directory first, finds matching filenames, and imports them. That way the logging module will have a wrong modname stored, and the constants used in Chat Announcements are undefined in the Prefab Counter constants module, causing the bad argument in the log.

Instead of shuffling the lookup order around, or doing other shenanigans with the package path, I'll use Klei's modimport() instead, despite its many shortcomings. It's good enough for small projects, and should not affect other mods in any way.

gyroplast added a commit that referenced this issue Oct 6, 2021
Manipulating GLOBAL.package.path to be able to use require() nicely
messes up the package.path for all mods being loaded after this one, so
it has to be avoided.

Klei's modinfo() function does not return a value, isn't cached nor
guarded against repeated inclusion, and "dependencies" need to be
resolved manually by importing in the correct order. All a bit iffy,
but for a project this size probably okay.

Fixes #12.
@gyroplast gyroplast mentioned this issue Oct 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant