Thread Tools Display Modes
12/05/16, 05:52 PM   #1
Rhyono
AddOn Author - Click to view addons
Join Date: Sep 2016
Posts: 659
UI failure

I've been experiencing some partial UI failure with an addon I've been working on, but I was able to reproduce the issue in a much smaller example. Using the example's functionality:
  1. Open your inventory.
  2. Type "/downitem " in chat and link a worn item in chat. Press enter.
  3. The downgraded (usually) result will appear in your chat. Now open the Champion interface.
  4. Start redistribution, end redistribution, try to start redistribution again (this will fail).
  5. Your UI should now be half useless. To fix it, type "/reloadui" in chat.

Test.txt
Code:
;Test

## Title: Test
## APIVersion: 100017
## Author: Test
## Description: Test
## Version: 1.0

Test.lua
Test.lua

Code:
local Test = {
	mame = "Test",
	author = "Test",
	version = "1.0"
}

--splits string into array
local function split_str(inputstr, sep)
	if sep == nil then
		sep = "%s"
	end
	local t={}
	local i=1
	for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
		t[i] = str
		i = i + 1
	end
	return t
end

--Tries to change an item's quality
local function GradeItem(text,inc)
	--break the string
	local item_data = split_str(text,":")
	local out = ""
	--increment the quality
	item_data[4] = tonumber(item_data[4])+inc
	if item_data[4] < 0 then
		item_data[4] = 0
	end	
	--reassemble
	local id = 1
	for id = 1, #item_data, 1 do
		out = out .. ":" .. item_data[id]
	end
	--output to chat
	CHAT_SYSTEM:AddMessage(out:sub(2))
end

--Grade handlers
local function UpgradeItem(text)
	return GradeItem(text,1)
end

local function DowngradeItem(text)
	return GradeItem(text,-1)
end

--Tries to upgrade an item's quality
SLASH_COMMANDS["/upitem"] = UpgradeItem
--Tries to downgrade an item's quality
SLASH_COMMANDS["/downitem"] = DowngradeItem
I know that it is a very lazy way of trying to change an item's quality and won't always work as planned (due to how convoluted quality can be), but it was a test piece. I'm hoping if someone can figure out what is triggering the UI failure, I can fix my real addon's problem.

Last edited by Rhyono : 12/05/16 at 07:40 PM.
  Reply With Quote
12/05/16, 07:10 PM   #2
Ayantir
 
Ayantir's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 1,019
This is a problem of leaking variables.

When an addon break something which have no relation with the thing which is broken, it's 99% times this.

Here is a better code, even untested

you were leaking Test, i, out variables.
also please avoid using ";" in lua.
it's accepted, but not recommended for readibility.
I know that 99% of new devs come from php or webdev.. but in this language ";" is not mandatory, just use carriage return

as other good practice, I would

not capitalize var names, but only functions names
avoid t, i, j, k and other tiny names. we're in a world where you have 75% chances that your project will be looked / used / served as reference / rewrited by someone else.
avoid doing function xxx.yyy() byt only local function yyy() when this function is not required to be used in another file.
even if for those two, it's my personal choices

Lua Code:
  1. local Test = {
  2.     Name = "Test",
  3.     Author = "Test",
  4.     Version = "1.0"
  5. }
  6.  
  7. --splits string into array
  8. local function split_str(inputstr, sep)
  9.     if sep == nil then
  10.         sep = "%s"
  11.     end
  12.     local t={}
  13.     local i=1
  14.     for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
  15.         t[i] = str
  16.         i = i + 1
  17.     end
  18.     return t
  19. end
  20.  
  21. --Tries to change an item's quality
  22. function Test.GradeItem(text,inc)
  23.     --break the string
  24.     local item_data = split_str(text,":")
  25.     local out = ""
  26.     --increment the quality
  27.     item_data[4] = tonumber(item_data[4])+inc
  28.     if item_data[4] < 0 then
  29.         item_data[4] = 0
  30.     end
  31.     --reassemble
  32.     for i = 1, #item_data, 1 do
  33.         out = out .. ":" .. item_data[i]
  34.     end
  35.     --output to chat
  36.     CHAT_SYSTEM:AddMessage(out:sub(2))
  37. end
  38.  
  39. --Grade handlers
  40. local function UpgradeItem(text)
  41.     return Test.GradeItem(text,1)
  42. end
  43.  
  44. local function DowngradeItem(text)
  45.     return Test.GradeItem(text,-1)
  46. end
  47.  
  48. --Tries to upgrade an item's quality
  49. SLASH_COMMANDS["/upitem"] = UpgradeItem
  50. --Tries to downgrade an item's quality
  51. SLASH_COMMANDS["/downitem"] = DowngradeItem

Last edited by Ayantir : 12/05/16 at 07:22 PM.
  Reply With Quote
12/05/16, 07:33 PM   #3
Rhyono
AddOn Author - Click to view addons
Join Date: Sep 2016
Posts: 659
Thanks for the pointers, but the failure still happens. I updated the first post with several mentioned changes, so if you see anything that would be leaking now, that'd be appreciated.

Last edited by Rhyono : 12/05/16 at 07:40 PM.
  Reply With Quote
12/06/16, 05:58 AM   #4
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,567
What exactly do you mean with a "partial UI failure"? do you get an error message, or does it change its look? Can you post some screenshots/videos please?

p.s. sidTools has a command "/st items" which allows you to manipulate item links freely. Maybe you should take a look at that.
  Reply With Quote
12/06/16, 12:11 PM   #5
Rhyono
AddOn Author - Click to view addons
Join Date: Sep 2016
Posts: 659
I'm not actually concerned with messing with the item link, it was just a way of reproducing the issue. There isn't a visible error, but part of the keyboard (e.g. Esc, F, X, R functionality) and clicking (trying to tele to a wayshrine, click on mail) stops registering. Nothing happens, at all. So in order to fix it, you have to use "/reloadui" or "/logout" since you can't even access the logout option in the menu.
  Reply With Quote
12/06/16, 12:34 PM   #6
Ayantir
 
Ayantir's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 1,019
Are you sure it's your code doing this ? The whole addon could help too.
  Reply With Quote
12/06/16, 04:24 PM   #7
Rhyono
AddOn Author - Click to view addons
Join Date: Sep 2016
Posts: 659
The main addon is much larger, but this piece of code as its own addon can cause the same failure. It also only happens after executing the code (not by simply having the addon enabled) and it is 100% reproducable.
  Reply With Quote
12/07/16, 12:41 AM   #8
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,913
Try to remove the chat_system function (comment it) and see if it's related to the chat output.
Decomment line for line or change the variable contents to simple values (like "hello") and see if this changes anything.

From the code snippet we are not able to find this error. We'd need the whole addon code to test it and "debug".

Did you turn off all other addons and the error will occur too?
  Reply With Quote
12/07/16, 10:48 AM   #9
Rhyono
AddOn Author - Click to view addons
Join Date: Sep 2016
Posts: 659
I'll try those suggestions tonight.

Originally Posted by Baertram View Post
From the code snippet we are not able to find this error. We'd need the whole addon code to test it and "debug".
This IS the whole addon. Forget about my main addon. This piece of code is a legitimate addon by itself and will cause the failure by itself. If you take these two pieces of code and put them into files with those names and put them in a folder named Test: it will function as an addon and cause the failure I've mentioned. Forget my main addon exists, this is an addon.
  Reply With Quote
12/07/16, 11:37 AM   #10
Ayantir
 
Ayantir's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 1,019
I just did a 10min vid long to figure that .. this code don't break anything.

A vid, some clues ?
this code can't break ui.
  Reply With Quote
12/07/16, 12:07 PM   #11
Rhyono
AddOn Author - Click to view addons
Join Date: Sep 2016
Posts: 659
None of the other addons I'm using have ever caused this issue directly themselves, but tonight I'll disable them all one by one and see if this addon will still cause the issue.

Edit: Has there been maintenance since I first posted this thread? I can't reproduce the problem anymore either. I'll post if it comes back, but I've been trying to cause it repeatedly and it doesn't happen.

Last edited by Rhyono : 12/07/16 at 07:34 PM.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » UI failure

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off