Thread Tools Display Modes
Prev Previous Post   Next Post Next
11-30-22, 10:54 PM   #1
Yakkers
A Deviate Faerie Dragon
Join Date: May 2020
Posts: 10
Trying to fix "Addon tried to call the protected function frame:SetPoint()"

I'm working on a simple addon that puts a little hotbar under your personal resource display so you can easily track your procs and cooldowns of the common abilities. I'm frequently getting the following error in bugsack, occurring when the personal resource display appears and the addon ties to attach its frame to it. It seems to mostly occur when there's some kind of state change like just landing from a ferry, a targeted NPC turning hostile which forces the bar to appear, etc.

[ADDON_ACTION_BLOCKED] AddOn 'Handybar' tried to call the protected function 'Handybar_Frame:SetPoint()'.

So,what my addon is doing is creating an event frame and main frame for the addon as such:
Lua Code:
  1. local eventFrame = CreateFrame("frame", "eventFrameHB")
  2. eventFrame:RegisterEvent("NAME_PLATE_UNIT_ADDED")
  3. eventFrame:RegisterEvent("NAME_PLATE_UNIT_REMOVED")
  4. eventFrame:RegisterEvent("ADDON_LOADED")
  5.  
  6. local HBFrame = CreateFrame("frame", "Handybar_Frame", UIParent)

Then, in InitializeHB() (which is called from the event handler a few blocks down) I'm creating the ability icon frames and aligning them up on the main frame, with iconList just being a list of action bar slot IDs I'm hardcoding per character in my script for the time being:
Lua Code:
  1. for i, v in ipairs(iconList) do
  2.     local newFrame = CreateFrame("CHECKBUTTON", "Handybar_ButtonFrame"..tostring(i), HBFrame, "SecureActionButtonTemplate, ActionBarButtonTemplate")
  3.     newFrame:SetPoint("LEFT", HBFrame, "CENTER", (i-1) * 48 - calculatedXOffset, 0)
  4.     newFrame:SetAttribute("type", "action")
  5.     newFrame:SetAttribute("action", v)
  6.     newFrame:SetScale(0.5)
  7.     newFrame:EnableMouse(false)
  8. end

Now here's my event handler. The SetPoint() on Line 7 here seems to be where the error is getting thrown.
Lua Code:
  1. eventFrame:SetScript("OnEvent", function(self, event, ...)
  2.     if event == "NAME_PLATE_UNIT_ADDED" then
  3.         if handybarVariables.attachToPRD then
  4.             if UnitIsUnit (..., "player") then
  5.                 HBFrame:ClearAllPoints()
  6.                 HBFrame:SetParent(C_NamePlate.GetNamePlateForUnit("player"))
  7.                 HBFrame:SetPoint("CENTER", C_NamePlate.GetNamePlateForUnit("player"), "CENTER", 0, yOffsetDefault)
  8.                 HBFrame:Show()
  9.             end
  10.         end
  11.     elseif event == "NAME_PLATE_UNIT_REMOVED" then
  12.         if handybarVariables.attachToPRD then
  13.             if UnitIsUnit (..., "player") then
  14.                 HBFrame:ClearAllPoints();
  15.                 HBFrame:Hide()
  16.                 HBFrame:SetParent(UIParent)
  17.             end
  18.         end
  19.     elseif event == "ADDON_LOADED" then
  20.         InitializeHB()
  21.         self:UnregisterEvent("ADDON_LOADED")
  22.     end
  23. end)


This code is largely copied from Weakauras' PRD attaching code, however it's possible that I didn't quite catch something. Is there anything obvious I'm doing wrong here? If it would be helpful I can pastebin the entire lua file or something as well.

This has been my dream addon for a long time and I'm working on hard on getting it stable enough to share. I did as much research as I could, but all the google results for this error are just talking about sending it to the addon devs and I couldn't find anything about it from the dev perspective.
  Reply With Quote
 

WoWInterface » Developer Discussions » Lua/XML Help » Trying to fix "Addon tried to call the protected function frame:SetPoint()"


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