Quantcast Nameplate addon causing c-stack overflow - WoWInterface
Thread Tools Display Modes
08-14-16, 02:02 PM   #1
Galaxy119
A Flamescale Wyrmkin
 
Galaxy119's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2014
Posts: 111
Nameplate addon causing c-stack overflow

My nameplate addon I use in my Diablo style UI is causing me a few issues. The issue occurs mainly in PVP but I would assume any enviornement where lots of nameplates are created in short periods, or possibly just after a certain amount of been created regardless of how long the period is. I'm not entierly sure, anyhow, the error comes from my function to change the name shown on the nameplate to add the units level and if they are elite/boss/rare to add a symbol tag. Here's the function:
Lua Code:
  1. --Name
  2. local f = CreateFrame("Frame")
  3. f:RegisterEvent("NAME_PLATE_UNIT_ADDED")
  4. f:SetScript("OnEvent", function(f, event, ...)
  5.     if event == "NAME_PLATE_UNIT_ADDED" then
  6.         local unit = ...
  7.         local nameplate = C_NamePlate.GetNamePlateForUnit(unit)
  8.         if not nameplate then return end
  9.        
  10.         hooksecurefunc("CompactUnitFrame_UpdateName", function (frame)
  11.         --Set the tag based on UnitClassification, can return "worldboss", "rare", "rareelite", "elite", "normal", "minus"
  12.         local tag
  13.         local level = UnitLevel(frame.unit)
  14.             if UnitClassification(frame.unit) == "worldboss" or UnitLevel(frame.unit) == -1 then
  15.                 tag = BossTag
  16.                 level = "??"
  17.             elseif UnitClassification(frame.unit) == "rare" or UnitClassification(frame.unit) =="rareelite" then
  18.                 tag = RareTag
  19.             elseif UnitClassification(frame.unit) == "elite" then
  20.                 tag = EliteTag
  21.             else
  22.                 tag = ""
  23.             end
  24.             --Set the nameplate name to include tag(if any), name and level
  25.             frame.name:SetText(UnitName(frame.unit).." ("..level..")"..tag)
  26.         end)
  27.     end
  28. end)
And here is the entire lua file for the addon: https://github.com/galaxy119/Roth_UI...NamePlates.lua
I'm assuming calling "CompactUnitFrame_UpdateName" that many times is causing the issue, but I don't know of another way to update the name whenever a new nameplate is created.
Code:
13x C stack overflow
[C]: ?
[C]: ?
[C]: ?
[C]: ?
[C]: ?
[C]: ?
[C]: ?
[C]: ?
[C]: ?
[C]: ?
[C]: ?
[C]: ?
...
[C]: ?
[C]: ?
[C]: ?
[C]: ?
[C]: in function `CompactUnitFrame_UpdateName'
FrameXML\CompactUnitFrame.lua:288: in function `CompactUnitFrame_UpdateAll'
FrameXML\CompactUnitFrame.lua:171: in function `CompactUnitFrame_SetUnit'
...eBlizzard_NamePlates\Blizzard_NamePlates.lua:270: in function `OnAdded'
...eBlizzard_NamePlates\Blizzard_NamePlates.lua:59: in function `OnNamePlateAdded'
...eBlizzard_NamePlates\Blizzard_NamePlates.lua:24: in function <...eBlizzard_NamePlates\Blizzard_NamePlates.lua:18>

Locals:
and
Code:
29x ...ack\Libs\CallbackHandler-1.0\CallbackHandler-1.0-6.lua:51: [string "safecall Dispatcher[2]"]:1: chunk has too many syntax levels
[C]: ?
...ack\Libs\CallbackHandler-1.0\CallbackHandler-1.0-6.lua:51: in function <...ack\Libs\CallbackHandler-1.0\CallbackHandler-1.0.lua:25>
...ack\Libs\CallbackHandler-1.0\CallbackHandler-1.0-6.lua:55: in function <...ack\Libs\CallbackHandler-1.0\CallbackHandler-1.0.lua:54>
...ack\Libs\CallbackHandler-1.0\CallbackHandler-1.0-6.lua:92: in function `Fire'
!BugGrabber\BugGrabber.lua:149: in function <!BugGrabber\BugGrabber.lua:147>
!BugGrabber\BugGrabber.lua:370: in function <!BugGrabber\BugGrabber.lua:292>
[C]: ?
[C]: ?
[C]: ?
[C]: ?
[C]: ?
[C]: ?
...
[C]: ?
[C]: ?
[C]: ?
[C]: ?
[C]: in function `CompactUnitFrame_UpdateName'
FrameXML\CompactUnitFrame.lua:288: in function `CompactUnitFrame_UpdateAll'
FrameXML\CompactUnitFrame.lua:171: in function `CompactUnitFrame_SetUnit'
...eBlizzard_NamePlates\Blizzard_NamePlates.lua:270: in function `OnAdded'
...eBlizzard_NamePlates\Blizzard_NamePlates.lua:59: in function `OnNamePlateAdded'
...eBlizzard_NamePlates\Blizzard_NamePlates.lua:24: in function <...eBlizzard_NamePlates\Blizzard_NamePlates.lua:18>

Locals:
  Reply With Quote
08-14-16, 06:29 PM   #2
jeruku
A Cobalt Mageweaver
 
jeruku's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 212
Too exhausted to scold, move hooks outside of hooked events/frames/functions.

Like so, and problem solved(maybe? not tested).
Lua Code:
  1. --removed stuff with no purpose
  2.  
  3. hooksecurefunc("CompactUnitFrame_UpdateName", function (frame)
  4.    --Set the tag based on UnitClassification, can return "worldboss", "rare", "rareelite", "elite", "normal", "minus"
  5.    local tag
  6.    local level = UnitLevel(frame.unit)
  7.    if UnitClassification(frame.unit) == "worldboss" or UnitLevel(frame.unit) == -1 then
  8.       tag = BossTag
  9.       level = "??"
  10.    elseif UnitClassification(frame.unit) == "rare" or UnitClassification(frame.unit) =="rareelite" then
  11.       tag = RareTag
  12.    elseif UnitClassification(frame.unit) == "elite" then
  13.       tag = EliteTag
  14.    else
  15.       tag = ""
  16.    end
  17.    --Set the nameplate name to include tag(if any), name and level
  18.    frame.name:SetText(UnitName(frame.unit).." ("..level..")"..tag)
  19. end)
  20.  
  21. -- deleted whatever was here
__________________
"I have not failed, I simply found 10,000 ways that did not work." - Thomas Edison
  Reply With Quote
08-14-16, 07:33 PM   #3
Galaxy119
A Flamescale Wyrmkin
 
Galaxy119's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2014
Posts: 111
Originally Posted by jeruku View Post
Too exhausted to scold, move hooks outside of hooked events/frames/functions.
Scold accepted. I am still learning LUA, I thought the only way to get it to update only the nameplate that was added was to make it do the change when it was added via event handler.
Originally Posted by jeruku
Like so, and problem solved(maybe? not tested).
Tested and working. Thank you.
  Reply With Quote
08-15-16, 12:37 AM   #4
Vlad
A Molten Giant
 
Vlad's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 792
If you put the hook somewhere it will be executed more than one time, it's not a good place to put a hook. :P
__________________
Profile: Curse | Wowhead
  Reply With Quote
08-15-16, 02:18 AM   #5
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Yeah, I've said that several times now... no hooks inside event handlers, use a hook or an event but not both. I feel like I should be assigning 100 repetitions on the chalkboard after school. >_>
__________________
Author/maintainer of Grid, PhanxChat, oUF_Phanx, and many more.
Troubleshoot an addonTurn any code into an addonMore addon resources
Need help with your code? Post all of your actual code! Attach or paste your files.
Please don’t PM me about addon bugs or code questions. Post a comment or forum thread instead!
  Reply With Quote
08-15-16, 03:02 AM   #6
Kanegasi
A Scalebane Royal Guard
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 440
Originally Posted by Galaxy119 View Post
Scold accepted. I am still learning LUA, I thought the only way to get it to update only the nameplate that was added was to make it do the change when it was added via event handler.
An event handler works exactly like hooksecurefunc, except for what triggers it. Events are obvious, but a hook is called every time the function it's hooking is called, no matter what called it. One or the other, not both.

For example, if I use hooksecurefunc('PlaySound',printsound) with printsound dumping the name of the sound to chat, it will print many uses of UI sounds in the default UI and any addons that use that function for sounds. In your case, WoW is already using the update function for the nameplates, it's better to hook that than rely on the event spam in combat.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Nameplate addon causing c-stack overflow

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