WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Nameplate addon causing c-stack overflow (https://www.wowinterface.com/forums/showthread.php?t=54211)

Joker119 08-14-16 02:02 PM

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:


jeruku 08-14-16 06:29 PM

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

Joker119 08-14-16 07:33 PM

Quote:

Originally Posted by jeruku (Post 317911)
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.
Quote:

Originally Posted by jeruku
Like so, and problem solved(maybe? not tested).

Tested and working. Thank you.

Vlad 08-15-16 12:37 AM

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

Phanx 08-15-16 02:18 AM

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. >_>

Kanegasi 08-15-16 03:02 AM

Quote:

Originally Posted by Galaxy119 (Post 317913)
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.


All times are GMT -6. The time now is 08:57 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI