Jump to content

Loading mod with Debug Mode enabled results in ArrayIndexOutOfBoundsException


ethanwdp

Recommended Posts

When loading my Cheat Menu mod with the game's Debug Mode enabled, I get the following error:

LOG  : Lua, 1581544592023> LuaManager.RunLua> Loading: C:/Users/Owner_/Zomboid/Workshop/Cheat Menu/Contents/mods/Cheat Menu/media/lua/client/ISUI/CheatCoreForCheatMenu.lua
LOG  : General, 1581544592025> [CHEAT MENU] CheatCore successfully loaded
LOG  : Lua, 1581544592026> LuaManager.RunLua> Loading: C:/Users/Owner_/Zomboid/Workshop/Cheat Menu/Contents/mods/Cheat Menu/media/lua/client/ISUI/CheatMenuCompassPresets.lua
LOG  : Lua, 1581544592027> LuaManager.RunLua> Loading: C:/Users/Owner_/Zomboid/Workshop/Cheat Menu/Contents/mods/Cheat Menu/media/lua/client/ISUI/CheatMenuHomeWindow.lua
LOG  : Lua, 1581544592027> LuaManager.RunLua> Loading: C:/Users/Owner_/Zomboid/Workshop/Cheat Menu/Contents/mods/Cheat Menu/media/lua/client/ISUI/CheatMenuTerraformTiles.lua
LOG  : Lua, 1581544592028> LuaManager.RunLua> Loading: C:/Users/Owner_/Zomboid/Workshop/Cheat Menu/Contents/mods/Cheat Menu/media/lua/client/ISUI/CrucibleUI/crucibleMain.lua
LOG  : Lua, 1581544592029> LuaManager.RunLua> Loading: C:/Users/Owner_/Zomboid/Workshop/Cheat Menu/Contents/mods/Cheat Menu/media/lua/client/ISUI/GenericInputWindow.lua
LOG  : Lua, 1581544592029> LuaManager.RunLua> Loading: C:/Users/Owner_/Zomboid/Workshop/Cheat Menu/Contents/mods/Cheat Menu/media/lua/client/ISUI/ISUICheatMenu.lua
Feb 12, 2020 4:56:32 PM zombie.Lua.LuaManager RunLua
SEVERE: Error found in LUA file: C:/Users/Owner_/Zomboid/Workshop/Cheat Menu/Contents/mods/Cheat Menu/media/lua/client/ISUI/ISUICheatMenu.lua
ERROR: General, 1581544592035> ExceptionLogger.logException> Exception thrown java.lang.ArrayIndexOutOfBoundsException: 200 at LexState.new_localvar line:762.
ERROR: General, 1581544592035> DebugLogStream.printException> Stack trace:
java.lang.ArrayIndexOutOfBoundsException: 200
	at org.luaj.kahluafork.compiler.LexState.new_localvar(LexState.java:762)
	at org.luaj.kahluafork.compiler.LexState.localstat(LexState.java:1648)
	at org.luaj.kahluafork.compiler.LexState.statement(LexState.java:1767)
	at org.luaj.kahluafork.compiler.LexState.chunk(LexState.java:1791)
	at org.luaj.kahluafork.compiler.LexState.block(LexState.java:1351)
	at org.luaj.kahluafork.compiler.LexState.test_then_block(LexState.java:1600)
	at org.luaj.kahluafork.compiler.LexState.ifstat(LexState.java:1611)
	at org.luaj.kahluafork.compiler.LexState.statement(LexState.java:1737)
	at org.luaj.kahluafork.compiler.LexState.chunk(LexState.java:1791)
	at org.luaj.kahluafork.compiler.LexState.body(LexState.java:1027)
	at org.luaj.kahluafork.compiler.LexState.simpleexp(LexState.java:1208)
	at org.luaj.kahluafork.compiler.LexState.subexpr(LexState.java:1304)
	at org.luaj.kahluafork.compiler.LexState.expr(LexState.java:1322)
	at org.luaj.kahluafork.compiler.LexState.explist1(LexState.java:1037)
	at org.luaj.kahluafork.compiler.LexState.assignment(LexState.java:1404)
	at org.luaj.kahluafork.compiler.LexState.exprstat(LexState.java:1697)
	at org.luaj.kahluafork.compiler.LexState.statement(LexState.java:1780)
	at org.luaj.kahluafork.compiler.LexState.chunk(LexState.java:1791)
	at org.luaj.kahluafork.compiler.LexState.compile(LexState.java:199)
	at se.krka.kahlua.luaj.compiler.LuaCompiler.loadis(LuaCompiler.java:132)
	at se.krka.kahlua.luaj.compiler.LuaCompiler.loadis(LuaCompiler.java:124)
	at zombie.Lua.LuaManager.RunLua(LuaManager.java:461)
	at zombie.Lua.LuaManager.RunLua(LuaManager.java:431)
	at zombie.Lua.LuaManager.LoadDirBase(LuaManager.java:279)
	at zombie.Lua.LuaManager.LoadDirBase(LuaManager.java:206)
	at zombie.Lua.LuaManager.LoadDirBase(LuaManager.java:324)
	at zombie.GameWindow.init(GameWindow.java:1008)
	at zombie.GameWindow.mainThreadInit(GameWindow.java:523)
	at zombie.GameWindow.mainThread(GameWindow.java:463)
	at java.lang.Thread.run(Thread.java:745)

It doesn't specify a line, but if I'm reading the error correctly then there's something about one of my if/then expressions that the compiler doesn't like. This only happens when Debug Mode is enabled, so I'm guessing that there's a conditional for the Debug flag somewhere in the game's code that modifies how the compiler handles expressions. Some insight on how to solve this would be greatly appreciated.

The Lua file that's encountering the error is over 600 lines long and I don't really expect anyone to dig through it, but I've attached it for good measure.

 

ISUICheatMenu.lua

Link to comment
Share on other sites

1 hour ago, Planet Algol said:

yeah, cheat menu does not work in debug mode, straight up.

 

1 hour ago, Planet Algol said:

Use necroforge instead.

That's why I made this thread, haha. It kinda sucks that some of my mod's users have turned to alternatives such as NF because of this issue, but I'm really not sure how to fix it.

Link to comment
Share on other sites

12 hours ago, ethanwdp said:

ERROR: General, 1581544592035> ExceptionLogger.logException> Exception thrown java.lang.ArrayIndexOutOfBoundsException: 200 at LexState.new_localvar line:762.

 

Kahlua has a limit of 200 local variables on any given stack. Your ISUICheatMenu.createMenuEntries function defines near 150 of them (minus a few in comments).

The local stack includes more then the 150 in your function,  the launching of debug mode is obviously introducing extra variables onto the stack that don't exist in normal launch.

 

Note not all 150 of yours will actively be on a stack, ones defined local in a "if" statement or other block should fall out of scope, but I'm not a expert on the kahlua internals and how it tracks the stack count.

 

Refactor your function into multiple smaller functions and blocks so un-needed variables fall out of scope faster, and/or reuse variables instead of declaring new ones.

 

 

Link to comment
Share on other sites

8 hours ago, Fenris_Wolf said:

 

Kahlua has a limit of 200 local variables on any given stack. Your ISUICheatMenu.createMenuEntries function defines near 150 of them (minus a few in comments).

The local stack includes more then the 150 in your function,  the launching of debug mode is obviously introducing extra variables onto the stack that don't exist in normal launch.

 

Note not all 150 of yours will actively be on a stack, ones defined local in a "if" statement or other block should fall out of scope, but I'm not a expert on the kahlua internals and how it tracks the stack count.

 

Refactor your function into multiple smaller functions and blocks so un-needed variables fall out of scope faster, and/or reuse variables instead of declaring new ones.

 

 

Refactoring the Vehicle submenu creation loop into a separate function seems to have fixed the error, so I guess now is a good time to get around to that rewrite I keep procrastinating on. Thank you so much for your help.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...