Thread Tools Display Modes
03/26/20, 02:15 PM   #1
Phinix
 
Phinix's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 186
Library race condition?

Hello,

So I have a library with functions I use in many of my addons. I set up this library as appropriate, with the ## IsLibrary: true tag and in the ## DependsOn: section of my other addons...

EDIT: Figured it out, thanks!

Last edited by Phinix : 03/26/20 at 04:44 PM.
  Reply With Quote
03/26/20, 02:21 PM   #2
Rhyono
AddOn Author - Click to view addons
Join Date: Sep 2016
Posts: 659
Were you bundling the lib with your addons for awhile? Did you ever do so without a txt file? If you use DependsOn, it shouldn't matter if it's a library or another addon: yours will be loaded after it. If someone can prove this happens with only MRL and your lib, that's when I'd blame ZOS.
  Reply With Quote
03/26/20, 02:28 PM   #3
Phinix
 
Phinix's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 186
Thanks for the quick reply!

Nope, not bundled. Addon is Master Recipe List and library is LibPhinixFunctions. Neither has been changed since they were last uploaded, and were working fine at the time. The only thing that changed is something in a patch between then and now. I have been away from the game for months and only came back to update as people were pointing out the sudden errors related to nil returns from a library that the addon is set to depend on.

EDIT: Problem was unrelated to addon dependency loading. Recipes in the MRL database were removed from the game in a recent patch requiring the database to be edited so reference to these no longer existing ID's didn't cause errors. The other thing with the library was a syntax typo that just happened to happen at the same time, causing me to jump the gun on the suspected cause.

Last edited by Phinix : 03/27/20 at 09:45 PM.
  Reply With Quote
03/26/20, 02:35 PM   #4
Rhyono
AddOn Author - Click to view addons
Join Date: Sep 2016
Posts: 659
Maybe I've just been lucky so far. None of my addons have had such an issue flagged.

Not ideal and I'm not sure if it would work but: you must be using such a function on load for it to be causing an error? By the time a player would get to a prov station, open their inventory, etc. the lib would be loaded regardless of order. Instead of the addon load event immediately initializing the addon, what about doing a lib check first and if the lib is nil, use a call later to retry your init X seconds later, repeating until the lib is finally loaded.
  Reply With Quote
03/26/20, 02:54 PM   #5
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,566
We are talking about this error, right?
Code:
user:/AddOns/MasterRecipeList/MasterRecipeList.lua:2430: operator .. is not supported for nil .. string
stack traceback:
user:/AddOns/MasterRecipeList/MasterRecipeList.lua:2430: in function 'NavigateScrollList'
|caaaaaa<Locals> list = 105, datalist = [table:1]{}, linktable = [table:2]{}, known = "|t16:16:/MasterRecipeList/bin/...", row = 2, i = 2, pos = 76, saved = 1, catstring = " (Alchemy)", linkname = "Bottle, Beaker", namestring = "Bottle, Beaker", preview = "" </Locals>|r
user:/AddOns/MasterRecipeList/MasterRecipeList.lua:4898: in function 'ESOMRL.XMLNavigation'
|caaaaaa<Locals> option = 304, n1 = 105 </Locals>|r
ESOMRL_MainFrameFurnitureFrameAlchemyButton5_Clicked:3: in function '(main chunk)'
|caaaaaa<Locals> self = ud, button = 1, ctrl = F, alt = F, shift = F, command = F </Locals>|r
Not sure what makes you think this is related to library loading?
The line in question contains this code:
Lua Code:
  1. searchTable[row] = { pos = pos, text = known..pTC(color,namestring)..catstring..preview, name = linkname }
The message tells you that you cannot concat nil with a string.

The only things concatenated here are "known", the return value of "pTC", "catstring" and "preview". The three local variables show up in the variable list below the line in the stack trace, so they are definitely not nil, which leaves only the return value of pTC. From what I see pTC refers to the function TColor in LibPhinixFunctions and the code looks like this:
Lua Code:
  1. function lib.TColor(color, text) -- Wraps the color tags with the passed color around the given text.
  2.     -- color:       String, hex format color string, for example "ffffff".
  3.     -- text:        The text to format with the given color.
  4.  
  5.     -- Example: PF.TColor("ff0000", "This is red.")
  6.     -- Returns: "|cff0000This is red.|r"
  7.  
  8.     if color == nil then
  9.         if lib.ASV.enableDebug then
  10.             d("LibPhinixFunctions: No color passed to TColor function.")
  11.         end
  12.         return
  13.     end
  14.     if text == nil then
  15.         if lib.ASV.enableDebug then
  16.             d("LibPhinixFunctions: No text passed to TColor function.")
  17.         end
  18.         return
  19.     end
  20.  
  21.     local cText = "|c"..tostring(color)..tostring(text).."|r"
  22.     return cText
  23. end
There are two ways for it to return nil. Either when color is nil or when text is nil. Looking at the variable list again we can see that namestring is "Bottle, Beaker", but the color variable is missing, so there we have the answer to why the error shows up.
The remaining question is, why is color nil? from what I see in the code it should be the return value of GetItemLinkQuality converted to a color string via a lookup table. From the item name we can deduce that the link in question is |H1:item:118299:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0|h|h which should return a quality of 5 and result in a color string of "eeca2a", but for some reason that's not the case here.
  Reply With Quote
03/26/20, 03:00 PM   #6
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
I thought the same some weeks ago Phinix.
Somehow I had erros which only happened if I tried to access the libraries at the beginning of my first loaded lua file in my addon.
The txt file had the library as ## DependsOn: so I thought all will be fine and the lib will be definately loaded BEFORE my addon's lua file is executed.
But sometimes it was working differently. Just coulnd't track down when.
As the lib was included into other addons (LibMainMenu) and even called hardcoded without ttx file I assumed it was somehting the other addons caused, cuz they don't use and txt file and DpendsOn tag.

I also told sirinsidiator about it and asked if it would make a difference if I move the libs "first" call in my lua file to my callback function of event_add_on_loaded, or if it is directly at teh start of the lua file.
He said it makes no difference as the ## (Optional)DependsOn handles the load of the library files properly before my lua file is loaded IF the lib got its own txt file and was added to my addon's ## DependsOn: tag.

All was setup properly, but I still got some error messages in the chat sometimes.

So I decided to move the lib stuff to the event_add_on_loaded callback function and since then the errors stopped. Might have been another addon or bad code somewhere. But also might be that there is somethign broken at the ZOs stuff of the dependencies under some circumstances...

Btw: This only happend with LibMainMenu for me so far so I really think it's because of other addons trying to access the lib to early. After cleaning up my addons and removing hardcoded lib calls most erros were gone as the addons were using the most up2date libraies directly from the AddOns directory, laoding them properly with their txt files.

So meanwhile I'd say it's not a general problem but related to the lib's loading and missing txt files, or wrong code somwhere.


@sirinsidiator:
pTC refers to the function TColor of LibPhinixFunctions. I can't find that in the list of the traceback?
So it might also be that pTC is just nil here cuz the lib LibPhinixFunctions function TColor is tried to be accessed before the library was loaded?

Last edited by Baertram : 03/26/20 at 03:10 PM.
  Reply With Quote
03/26/20, 03:07 PM   #7
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,566
Originally Posted by Baertram View Post
@sirinsidiator:
pTC refers to the function TColor of LibPhinixFunctions .
So it might also be that pTC is just nil here cuz the lib LibPhinixFunctions function TColor is tried to be accessed before the library was loaded?
No. If that were the case the error would be "attempt to call local 'pTC' (a nil value)".
  Reply With Quote
03/26/20, 03:14 PM   #8
Phinix
 
Phinix's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 186
@sirinsidiator - Thanks for taking a look.

EDIT: May have worked it out, testing...

Last edited by Phinix : 03/26/20 at 03:28 PM.
  Reply With Quote
03/26/20, 03:18 PM   #9
Scootworks
 
Scootworks's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2014
Posts: 312
Originally Posted by Phinix View Post
@sirinsidiator - Thanks for taking a look. It is difficult to troubleshoot because there is a lot of code here. But I suspect if you manually plug a color value in place of that function so it cannot possibly be nil the return will still be nil, based on other experiece I am having with this (similar to what Baertram describes).

For example, correcting the above I immediately get an error referencing line 150 of MasterRecipeList\bin\SetupPreFrames.lua which looks like:

Code:
for k = 1, 1895 do ESOMRL.FurnitureRecipes[pLI(ESOMRL.FurnitureTable[k].link)] = {position = k} end
pLI is a local alias defined at the top of the same file for LibPhinixFunctions.GetItemIdFromLink, which looks like this:

Code:
function lib.GetItemIdFromLink(itemLink)-- Parse an item link for the itemId.
    local itemId = select(4, ZO_LinkHandler_ParseLink(itemLink))
    -- itemLink: Either generated from the UI/Events/Functions or manually as a link string in quotes

    if itemLink == nil then
        if lib.ASV.enableDebug then
            d("LibPhinixFunctions: No link passed to GetItemIdFromLink function.")
        end
        return
    end

    if itemId then
        return tonumber(itemId)
    else
        if lib.ASV.enableDebug then d("LibPhinixFunctions: No valid link passed to GetItemIdFromLink function.") end
    end
end
I also tried just parsing the link string with gsub, but the problem is that the function is immediately returning nil without actually processing, until the addon depending on it is fully loaded.

Again these functions were all working before the recent patches since it was uploaded, and working around one error immediately results in a new one, basically for ANY call to this library.

I will try what Baertram suggests but this is also difficult as some of the calls are loaded in files of this addon that load from the manifest before the one which actually contains the event_add_on_loaded callback.

Could that be the problem?
btw there is a function to get itemId:

Lua Code:
  1. GetItemLinkItemId(string itemLink)
  2. Returns: number itemId
  Reply With Quote
03/26/20, 03:27 PM   #10
Phinix
 
Phinix's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 186
Thanks Scoot, is that new? I remember not finding that in the ESOUI function database on UESP back in the day.

Also I think I might have figured it out... Some of the recipes in the current MRL database may have been since removed from the game and so looking up their quality level is returning nil.

The other thing I posted appears to be a separate issue and maybe resolved, will update...

Last edited by Phinix : 03/27/20 at 09:47 PM.
  Reply With Quote
03/26/20, 03:28 PM   #11
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,566
Originally Posted by Phinix View Post
For example, correcting the above I immediately get an error referencing line 150 of MasterRecipeList\bin\SetupPreFrames.lua which looks like:
Can you please post the error? Otherwise it's impossible to tell why you get it. Regardless I am still convinced that the library loading has nothing to do with it. I use lots of libraries before EVENT_ADD_ON_LOADED and never had any issues with it. If what you and Baertram say is really the case, I am either incredibly lucky to have 0 reports regarding this over the past 6 years, or you are simply mistaken in your analysis of the problem at hand.
  Reply With Quote
03/26/20, 03:37 PM   #12
Rhyono
AddOn Author - Click to view addons
Join Date: Sep 2016
Posts: 659
Last major update removed a huge number of blueprints, so that would be a reasonable source for nils from links you were constructing via an internal list of ids.
  Reply With Quote
03/26/20, 03:38 PM   #13
Scootworks
 
Scootworks's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2014
Posts: 312
Originally Posted by Phinix View Post
Thanks Scoot, is that new? I remember not finding that in the ESOUI function database on UESP back in the day.

Also I think I might have figured it out... Some of the recipes in the current MRL database may have been since removed from the game and this looking up their quality level is returning nil.

The other thing I posted appears to be a separate issue and maybe resolved, will update...
oh idk, maybe yes, maybe not
  Reply With Quote
03/26/20, 04:06 PM   #14
Phinix
 
Phinix's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 186
@Rhyono yep that is definitely it.

The other library errors I was getting turned out to be just me being rusty and messing up the syntax while converting away from LibStub (used ':' instead of '.' as a constructor between the global library table and the function definition, adding an extra 'self' variable to them all and throwing off the values. DOH!

@sirinsidiator you were correct, dependency checking had nothing to do with it!

Last edited by Phinix : 03/27/20 at 09:47 PM.
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » Library race condition?

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