ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   UI failure (https://www.esoui.com/forums/showthread.php?t=6665)

Rhyono 12/05/16 05:52 PM

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.

Ayantir 12/05/16 07:10 PM

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

Rhyono 12/05/16 07:33 PM

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.

sirinsidiator 12/06/16 05:58 AM

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.

Rhyono 12/06/16 12:11 PM

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.

Ayantir 12/06/16 12:34 PM

Are you sure it's your code doing this ? The whole addon could help too.

Rhyono 12/06/16 04:24 PM

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.

Baertram 12/07/16 12:41 AM

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?

Rhyono 12/07/16 10:48 AM

I'll try those suggestions tonight.

Quote:

Originally Posted by Baertram (Post 29079)
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.

Ayantir 12/07/16 11:37 AM

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.

Rhyono 12/07/16 12:07 PM

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.


All times are GMT -6. The time now is 05:22 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI