Jump to content

Issue with UIManager


Narrnika

Recommended Posts

For the test, create a simple mod with a single lua-file, in which we write the following code (no matter what for - it's just a shortcut to confirm the bug):

require "OptionScreens/ModSelector"
require "ISUI/ISLabel"

local def_create = ModSelector.create

function ModSelector:create()
	def_create(self)
	
	self.test = ISLabel:new(0, 0, 17, "test", 1, 1, 1, 1, UIFont.Small, true)
	self.test:addToUIManager()
	--self.test:removeFromUIManager()
end

Such a mod turns on without errors, but if you want to enable something else or disable this mod, the following will happen:

ERROR: General     , 1610142050060> ExceptionLogger.logException> Exception thrown java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 at ArrayList.rangeCheck line:657.
ERROR: General     , 1610142050061> DebugLogStream.printException> Stack trace:
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
	at java.util.ArrayList.rangeCheck(ArrayList.java:657)
	at java.util.ArrayList.get(ArrayList.java:433)
	at zombie.ui.UIManager.update(UIManager.java:765)
	at zombie.GameWindow.logic(GameWindow.java:246)
	at zombie.core.profiling.AbstractPerformanceProfileProbe.invokeAndMeasure(AbstractPerformanceProfileProbe.java:71)
	at zombie.GameWindow.frameStep(GameWindow.java:721)
	at zombie.GameWindow.run_ez(GameWindow.java:637)
	at zombie.GameWindow.mainThread(GameWindow.java:464)
	at java.lang.Thread.run(Thread.java:748)

It is important that the error occurs after `Core.ResetLua` function is executed, that is, when our mod is already disabled. In addition, if you look at the function `UIManager.update` in which the error occurs, there are a couple more oddities. In the decompiler, this code looks like this (line numbering is preserved, missing numbers are probably occupied by curly braces):

760:	if (Mouse.isLeftReleased()) {
762:		n = 0;
763:		for (int i1 = UI.size() - 1; i1 >= 0; i1--) {
765:			UIElement uIElement = UI.get(i1);

Log points to line 765, but we cannot get there at this moment (after restarting Lua). Firstly, because of the condition `Mouse.isLeftReleased()`, and secondly, `UI.size()` at this moment is 0, that is, there should not be a single iteration.

 

Note 1: In test Lua-code has commented line. If you uncomment it (that is, delete the object immediately after creation), then the error does not occur. However, if you use this line directly before calling the `Core.ResetLua` function (for example, in the `ModSelector:onAccept` function), it does not help and the error continues to appear.

Note 2: Instead of `ISLabel`, there can be any other UI-element. The problem arises precisely from adding it as a new layer, but not as a child element.

 

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...