Sarcen Posted January 19, 2015 Share Posted January 19, 2015 Bug Submission: Category: Client Crash Issue Title: Modding: AddPlayerPostInit(...) crashes if EnableModDebugPrint() is active. Issue Description: AddPlayerPostInit(...) crashes if EnableModDebugPrint() is active. Cause: Line 46 of modutil.lua assumes mod is at stack level 3, but in AddPlayerPostInit its at 4 (AddPlayerPostInit calls AddPrefabPostInitAny that calls initprint) Relevant Log: [string "scripts/modutil.lua"]:46: variable 'modname' is not declared LUA ERROR stack traceback: =[C] in function 'error' scripts/strict.lua(23,1) scripts/modutil.lua(46,1) in function 'initprint' scripts/modutil.lua(236,1) in function 'AddPrefabPostInitAny' scripts/modutil.lua(242,1) in function 'AddPlayerPostInit' ../mods/workshop-373991022/modmain.lua(51,1) in main chunk =[C] in function 'xpcall' scripts/util.lua(455,1) in function 'RunInEnvironment' scripts/mods.lua(319,1) in function 'InitializeModMain' scripts/mods.lua(300,1) in function 'LoadMods' scripts/main.lua(244,1) in function 'ModSafeStartup' scripts/main.lua(292,1) =[C] in function 'SetPersistentString' scripts/mainfunctions.lua(24,1) in function 'SavePersistentString' scripts/modindex.lua(76,1) =[C] in function 'GetPersistentString' scripts/modindex.lua(63,1) in function 'BeginStartupSequence' scripts/main.lua(291,1) in function 'callback' scripts/modindex.lua(342,1) =[C] in function 'GetPersistentString' scripts/modindex.lua(322,1) in function 'Load' scripts/main.lua(290,1) in main chunk Steps to Reproduce: EnableModDebugPrint() in modsettings.lua AddPlayerPostInit(...) in a modmain.lua Link to comment Share on other sites More sharing options...
Developer PeterA Posted January 19, 2015 Developer Share Posted January 19, 2015 @Sarcen, thanks for reporting this! I don't have a fix for this yet, but it may have helped me uncover another issue that I'd been tracking down. Link to comment Share on other sites More sharing options...
Muche Posted December 31, 2015 Share Posted December 31, 2015 Maybe something like this would help? --- modutil.lua +++ modutil.patch.lua @@ -70,9 +70,20 @@ local function RemoveDefaultCharacter(name) end end +local function getfenvminfield(level, fieldname) + level = level + 1 -- increase level due to this function call + -- tail call doesn't have full debug info, its func is nil + -- use rawget to circumvent strict.lua's checks of _G that we might hit + while debug.getinfo(level) ~= nil and (debug.getinfo(level).func == nil or rawget(getfenv(level), fieldname) == nil) do + level = level + 1 + end + assert(debug.getinfo(level) ~= nil, "Field " .. tostring(fieldname) .. " not found in callstack's functions' environments") + return getfenv(level)[fieldname] +end + local function initprint(...) if KnownModIndex:IsModInitPrintEnabled() then - local modname = getfenv(3).modname + local modname = getfenvminfield(3, "modname") print(ModInfoname(modname), ...) end end Link to comment Share on other sites More sharing options...
Muche Posted March 1, 2016 Share Posted March 1, 2016 Patch reformatted (added newlines lost during forum upgrade). Link to comment Share on other sites More sharing options...
Developer Ipsquiggle Posted April 6, 2016 Developer Share Posted April 6, 2016 Thanks for the fix, @Muche. This will be in the next update. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.
Please be aware that the content of this thread may be outdated and no longer applicable.