Thread Tools Display Modes
05/14/16, 01:32 AM   #1
Letho
AddOn Author - Click to view addons
Join Date: Apr 2016
Posts: 238
Strange Lua Error

Hello fellow coders,
I'm currently running into an issue that i am not able to resolve. I'm getting this error from time to time, sometimes just on login, sometimes when clicking on sth.



I'm not really experienced at coding lua, but as far as i know the error message should at least provide some information on the addon or file that produces it. The long numeric value doesnt look like a memory adress to me and it could be referring to a 'line 3', but where exactly? and whats does "function '(main chunk)'" represent?

Thx in advance and cheers,
Letho
  Reply With Quote
05/14/16, 01:58 AM   #2
votan
 
votan's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 577
Originally Posted by Letho View Post
Hello fellow coders,
I'm currently running into an issue that i am not able to resolve. I'm getting this error from time to time, sometimes just on login, sometimes when clicking on sth.



I'm not really experienced at coding lua, but as far as i know the error message should at least provide some information on the addon or file that produces it. The long numeric value doesnt look like a memory adress to me and it could be referring to a 'line 3', but where exactly? and whats does "function '(main chunk)'" represent?

Thx in advance and cheers,
Letho
This is a hard to find error. The generic number as function name indicates an anonymous (nameless) function. "(main chunk)" as the only caller in the callstack indicates it is called directly from C++ buildin code.

If you say, it is just from time to time, I would guess it is a timing problem from an <OnUpdate> event handler.

Which addons are you using? Which are using UI xml files with <OnUpdate>?
  Reply With Quote
05/14/16, 02:32 AM   #3
Letho
AddOn Author - Click to view addons
Join Date: Apr 2016
Posts: 238
Hey, thx for your reply!

It must be somewhere in the addon that i am currently developing, strangely the only OnUpdate-functionality i use is

lua Code:
  1. EVENT_MANAGER:RegisterForUpdate(AuraMastery.name, AuraMastery.savedVariables.updateSpeed, AuraMastery.updateHandler);
  2.  
  3. [...]
  4.  
  5. function AuraMastery.updateHandler()
  6.     local n = AuraMastery:GetNumElements(AuraMastery.loadedAuras);
  7.     --d(tostring(AuraMastery.activeAura));
  8.     for k, v in pairs(AuraMastery.loadedAuras) do
  9.         AuraMastery:UpdateBar(v);
  10.     end
  11. end

this updatehandler is definetely working as intended, otherwise my addon would throw many errors at me^^

It must have sth. to do with the addon menu itself, it's containing many editboxes with OnMouse..., OnFocus... - handlers, but of course no OnUpdate :/

The bug only occurs if my addon is loaded, but it seems to occur absolutely randomly.
  Reply With Quote
05/14/16, 03:02 AM   #4
votan
 
votan's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 577
Originally Posted by Letho View Post
Hey, thx for your reply!

It must be somewhere in the addon that i am currently developing, strangely the only OnUpdate-functionality i use is

lua Code:
  1. EVENT_MANAGER:RegisterForUpdate(AuraMastery.name, AuraMastery.savedVariables.updateSpeed, AuraMastery.updateHandler);
  2.  
  3. [...]
  4.  
  5. function AuraMastery.updateHandler()
  6.     local n = AuraMastery:GetNumElements(AuraMastery.loadedAuras);
  7.     --d(tostring(AuraMastery.activeAura));
  8.     for k, v in pairs(AuraMastery.loadedAuras) do
  9.         AuraMastery:UpdateBar(v);
  10.     end
  11. end

this updatehandler is definetely working as intended, otherwise my addon would throw many errors at me^^

It must have sth. to do with the addon menu itself, it's containing many editboxes with OnMouse..., OnFocus... - handlers, but of course no OnUpdate :/

The bug only occurs if my addon is loaded, but it seems to occur absolutely randomly.
Where and when do you call EVENT_MANAGER:RegisterForUpdate? EVENT_ADD_ON_LOADED, EVENT_PLAYER_ACTIVATED?
  Reply With Quote
05/14/16, 05:35 AM   #5
Letho
AddOn Author - Click to view addons
Join Date: Apr 2016
Posts: 238
This is the whole initialization, i call it directly at the beginning of the addon logic.

lua Code:
  1. AuraMastery                 = {}
  2. AuraMastery.name            = "AuraMastery"
  3. AuraMastery.version         = "0.01a"
  4. AuraMastery.author      = "Letho"
  5.  
  6. -- locals
  7. local WM = WINDOW_MANAGER;
  8. local profileDefaults       = {
  9.     updateSpeed             = 100,
  10.     activeProfile           = 1,
  11.     profiles                    = {
  12.         ["profileNames"]    = {
  13.             [1]                 = "default",
  14.         },
  15.         ["profileData"]     = {
  16.             [1] = {
  17.                 ['auraData'] = {};
  18.             },
  19.         }
  20.     }  
  21. };
  22. AuraMastery.activeEffects   = {};
  23. AuraMastery.trackedEvents   = {
  24.     ['EVENT_EFFECT_CHANGED'] = {
  25.         ['abilityIds'] = {};
  26.     }
  27. };
  28. AuraMastery.loadedAuras     = {};
  29. AuraMastery.auraAbilityIds = {};
  30. AuraMastery.menuHidden      = true;
  31.  
  32. -- initialization
  33. function AuraMastery.OnAddOnLoaded(event, addonName)
  34.     if addonName ~= AuraMastery.name then return end   
  35.     EVENT_MANAGER:UnregisterForEvent(AuraMastery.name, EVENT_ADD_ON_LOADED);
  36.     AuraMastery:Initialize();
  37. end
  38.  
  39. function AuraMastery:Initialize()
  40.     self:LoadProfileData();
  41.     self:InitializeControls();
  42.    
  43.     EVENT_MANAGER:RegisterForEvent(AuraMastery.name, EVENT_EFFECT_CHANGED, AuraMastery.OnEffectEvent);
  44.     EVENT_MANAGER:RegisterForUpdate(AuraMastery.name, AuraMastery.savedVariables.updateSpeed, AuraMastery.updateHandler);
  45. end
  46.  
  47. function AuraMastery:LoadProfileData()
  48.     self.savedVariables = ZO_SavedVars:New("AuraMasterySavedVariables", 1, nil, profileDefaults);
  49.     self.svars = self.savedVariables.profiles.profileData[self.savedVariables.activeProfile];
  50. end
  51.  
  52. local function slashHandler(userInput)
  53.     local parsedUserInput = {string.match(userInput,"^(%S*)%s*(.-)$")}
  54.     local command = {}
  55.     local n = #parsedUserInput;
  56.     for i=1, n do
  57.         if (parsedUserInput[i] ~= nil and parsedUserInput[i] ~= "") then
  58.             command[i] = string.lower(parsedUserInput[i]);
  59.         end
  60.     end
  61.  
  62.     if ("unlock" == command[1]) then
  63.         for k, v in pairs(AuraMastery.aura) do
  64.             AuraMastery:UnloadAuras();
  65.             v:SetHidden(false);
  66.             v:SetMouseEnabled(true);
  67.             v:SetMovable(true);
  68.             SetGameCameraUIMode(true);
  69.         end
  70.         d("Auras unlocked.");
  71.     end
  72.    
  73.     if ("lock" == command[1]) then
  74.         for k, v in pairs(AuraMastery.aura) do
  75.             AuraMastery:LoadAura(k);
  76.             v:SetHidden(true);
  77.             v:SetMouseEnabled(false);
  78.             v:SetMovable(false);
  79.             SetGameCameraUIMode(false);
  80.         end
  81.         d("Auras locked.");
  82.     end
  83.  
  84.     if ("menu" == command[1]) then
  85.         local container = WM:GetControlByName("AuraMasteryMenuContainer");
  86.         --self:CreateMenu();
  87.         if (container:IsHidden()) then
  88.             container:SetHidden(false);
  89.         else
  90.             container:SetHidden(true);
  91.         end
  92.     end
  93.  
  94.     if ("tex" == command[1]) then
  95.         AuraMastery:Tex();
  96.     end
  97. end
  98. SLASH_COMMANDS["/am"] = slashHandler;
  99.  
  100. EVENT_MANAGER:RegisterForEvent(AuraMastery.name, EVENT_ADD_ON_LOADED, AuraMastery.OnAddOnLoaded);
  Reply With Quote
05/14/16, 05:40 AM   #6
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,578
Errors like this are usually caused by functions that are called from an xml file.
Do you use any xml controls in your addon?
  Reply With Quote
05/14/16, 06:48 AM   #7
Letho
AddOn Author - Click to view addons
Join Date: Apr 2016
Posts: 238
Hey sirinsidiator, thx for your reply!

Yes, I preload my whole addon menu by loading it from an xml file on addon start (im gonna implement a "only load menu controls if called" - functionality later). All event handlers are working as intended, is there any rule that there must be some standard handlers set up for any specific control?
  Reply With Quote
05/14/16, 11:13 AM   #8
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,578
When you use xml files, you should make sure that all functions that you use inside the xml file are already defined when it is loaded, otherwise you may see errors like the one you posted.

Simply put xml files after your lua files in the manifest and only try access the controls after EVENT_ADDON_LOADED was fired for your addon.
  Reply With Quote
05/14/16, 11:18 AM   #9
Letho
AddOn Author - Click to view addons
Join Date: Apr 2016
Posts: 238
D'OH, Letho is so stupid That solved the issue, thank you very much =)
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Strange Lua Error


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