Thread Tools Display Modes
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
12-01-22, 01:34 AM   #2
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,360
You cannot affect movement (setpoint) or visibility changes (show/hide) on secure frames in-combat.

You'd need to use a secure header to control visibility (within the macro system options constraints).

But it looks to me that your problem has a much easier solution.

If your buttons that you are trying to attach to your personal resource display are not meant to be clickable to cast but instead just show cooldown and such information about your abilities, you do not need to have them inherit secure templates `SecureActionButtonTemplate` and you'd sidestep the whole problem.
  Reply With Quote
12-07-22, 12:12 AM   #3
Yakkers
A Deviate Faerie Dragon
Join Date: May 2020
Posts: 10
Originally Posted by Dridzt View Post
You cannot affect movement (setpoint) or visibility changes (show/hide) on secure frames in-combat.

You'd need to use a secure header to control visibility (within the macro system options constraints).

But it looks to me that your problem has a much easier solution.

If your buttons that you are trying to attach to your personal resource display are not meant to be clickable to cast but instead just show cooldown and such information about your abilities, you do not need to have them inherit secure templates `SecureActionButtonTemplate` and you'd sidestep the whole problem.
Thanks so much. Knowing that it's related to being in combat helps a lot with troubleshooting too, because now I know I can just walk into a hostile mob without targeting to trigger it. However, I tried removing SecureActionButtonTemplate so it just reads as this:

Lua Code:
  1. local newFrame = CreateFrame("CHECKBUTTON", "Handybar_ButtonFrame"..tostring(i), HBFrame, "ActionBarButtonTemplate")

and I'm still seeing the problem. Is that still not set up correctly? My goal here is to just create a frame that looks exactly like an action bar slot but is not at all interactive.

Alternatively, I'm looking into headers here but I don't see anything about headers for the buttons, they seem to do very particular things relating to other stuff like party frames and buffs/debuffs.
  Reply With Quote
12-09-22, 05:44 AM   #4
Taudier
A Wyrmkin Dreamwalker
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 53
Originally Posted by Yakkers View Post
Thanks so much. Knowing that it's related to being in combat helps a lot with troubleshooting too, because now I know I can just walk into a hostile mob without targeting to trigger it. However, I tried removing SecureActionButtonTemplate so it just reads as this:

Lua Code:
  1. local newFrame = CreateFrame("CHECKBUTTON", "Handybar_ButtonFrame"..tostring(i), HBFrame, "ActionBarButtonTemplate")

and I'm still seeing the problem. Is that still not set up correctly? My goal here is to just create a frame that looks exactly like an action bar slot but is not at all interactive.

Alternatively, I'm looking into headers here but I don't see anything about headers for the buttons, they seem to do very particular things relating to other stuff like party frames and buffs/debuffs.
because ActionBarButtonTemplate inherits SecureActionButtonTemplate
  Reply With Quote
12-09-22, 01:42 PM   #5
Yakkers
A Deviate Faerie Dragon
Join Date: May 2020
Posts: 10
Originally Posted by Taudier View Post
because ActionBarButtonTemplate inherits SecureActionButtonTemplate
Yeah, I've been doing a lot of research and experimenting with this since then and that seems to be the case.

It's starting to look like what I'm trying to do here maybe isn't really possible, unfortunately it's just a symptom of the fact that the PRD can potentially be a new frame every time it appears which forces me to call SetPoint in combat occasionally.

I might make a new thread for this just because the focus has evolved and the subject doesn't have anything to do with what I'm trying to do anymore, but are there potentially any ways to display a non-clickable moveable action bar slot that doesn't care about taint? Or alternatively would there possibly be some trick to snap my frame to the PRD maybe like right before InCombatLockdown ticks on?
  Reply With Quote
12-09-22, 08:51 PM   #6
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,360
You essentially want to replicate the visual appearance of actionbuttons without making them secure frames.

If they are not secure frames then anchoring them to your personal resource display in-combat or not is not an issue.

So shift your focus to that would be the suggestion.

The easiest way would probably be to create a "actionbutton lookalike" display with weakauras and anchor it to that frame.

Example: https://wago.io/9HqgUhL-q
  Reply With Quote
12-12-22, 05:58 PM   #7
Yakkers
A Deviate Faerie Dragon
Join Date: May 2020
Posts: 10
Originally Posted by Dridzt View Post
You essentially want to replicate the visual appearance of actionbuttons without making them secure frames.

If they are not secure frames then anchoring them to your personal resource display in-combat or not is not an issue.

So shift your focus to that would be the suggestion.

The easiest way would probably be to create a "actionbutton lookalike" display with weakauras and anchor it to that frame.

Example: https://wago.io/9HqgUhL-q
This is actually what I used to do, but I was looking for a more direct solution since setting up these weakauras can get incredibly complex when you have various procs and glow states and the like and sometimes charge abilities don't quite render right, after enough time spent scripting all those states really just trying to duplicate the action bar buttons I thought "why don't I look into the API and see if it can just... do that?"

For now I've found a "good enough" solution by just setting the PRD to always be visible, alternatively I might just anchor the displays at a fixed point onscreen and get used to viewing them like that instead of moving with my health bar. I would still love to find a way to snap these to my PRD and have it properly hide/show if possible, but if it's not possible, I can live without it.
  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