Jump to content
Narrnika

Issue with UIManager

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.

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...