Thread Tools Display Modes
11-21-17, 12:57 PM   #1
Marsgames
An Aku'mai Servant
 
Marsgames's Avatar
Join Date: Jul 2016
Posts: 33
C Stack Overflow

Hey,

I think my addon is causing a C Stack Overflow.
I think it's creating more frame each time the function is called but I don't really understand hoow it works.

My function is
Lua Code:
  1. function poseDot()
  2.  local iter = 0
  3.     hooksecurefunc("ContainerFrame_Update",function(self)
  4.             local bag = self:GetID() -- container's ID is the bag number
  5.             --print("aze : "..bag)
  6.             iter = iter + 1
  7.             for i=1,self.size do
  8.                 local button=_G[self:GetName().."Item"..i]
  9.                 local slot = button:GetID() -- button's ID is slot number
  10.                 local itemLink = GetContainerItemLink(bag, slot)
  11.  
  12.                 if itemLink ~= nil then
  13.                     if button.overlay then
  14.                         button.overlay:SetShown(false)
  15.                         button.overlay = nil
  16.                         --button=_G[self:GetName().."Item"..i]
  17.                     end
  18.                     --print(itemLink)
  19.                     local weightCalcResult = weightCalculation(itemLink)
  20.                     if weightCalcResult[1] ~= nil and weightCalcResult[1] > 0 or weightCalcResult[2] ~= nil and weightCalcResult[2] > 0 then
  21.                         --local itemId = tonumber(parseID(itemLink))
  22.  
  23.                         -- create overlay texture if it doesn't exit for the button
  24.                         if not button.overlay then
  25.                             button.overlay = button:CreateTexture(nil,"OVERLAY")
  26.                             button.overlay:SetSize(18,18)
  27.                             button.overlay:SetPoint("TOPLEFT")
  28.                             button.overlay:SetTexture("Interface\\AddOns\\GearHelper\\Textures\\flecheUp")
  29.                             --button.overlay:SetTexture("Interface\\Common\\Indicator-Green")
  30.                             button.overlay:SetShown(true)
  31.                         end
  32.                     end
  33.                     weightCalcResult = nil
  34.                 end
  35.                 button = nil
  36.                 slot = nil
  37.                 itemLink = nil
  38.             end
  39.             bag = nil
  40.             self = nil
  41.  
  42.     end)
  43. end

It's called every time I open my bag.

I'll edit this post, to show you error when it apear.







Issue :
Lua Code:
  1. 232x C stack overflow
  2. [C]: ?
  3. [C]: ?
  4. [C]: ?
  5. [C]: ?
  6. [C]: ?
  7. [C]: ?
  8. [C]: ?
  9. [C]: ?
  10. [C]: ?
  11. [C]: ?
  12. [C]: ?
  13. [C]: ?
  14. ...
  15. [string "*:OnShow"]:1: in function <[string "*:OnShow"]:1>
  16. [C]: in function `Show'
  17. FrameXML\ContainerFrame.lua:843: in function `ContainerFrame_GenerateFrame'
  18. FrameXML\ContainerFrame.lua:93: in function <FrameXML\ContainerFrame.lua:77>
  19. [C]: in function `ToggleBag'
  20. FrameXML\ContainerFrame.lua:115: in function `ToggleBackpack'
  21. FrameXML\ContainerFrame.lua:330: in function `OpenBackpack'
  22. FrameXML\ContainerFrame.lua:1276: in function <FrameXML\ContainerFrame.lua:1253>
  23. [C]: in function `ToggleAllBags'
  24. [string "OPENALLBAGS"]:1: in function <[string "OPENALLBAGS"]:1>
  25.  
  26. Locals:
  27. (*temporary) = ContainerFrame1 {
  28.  0 = <userdata>
  29.  PortraitButton = ContainerFrame1PortraitButton {
  30.  }
  31.  Portrait = ContainerFrame1Portrait {
  32.  }
  33.  ClickableTitleFrame = <unnamed> {
  34.  }
  35.  bags = <table> {
  36.  }
  37.  FilterDropDown = ContainerFrame1FilterDropDown {
  38.  }
  39.  bagsShown = 1
  40.  FilterIcon = <unnamed> {
  41.  }
  42.  allBags = true
  43.  size = 16
  44. }
  45. (*temporary) = <function> defined =[C]:-1
  46. (*temporary) = ContainerFrame1 {
  47.  0 = <userdata>
  48.  PortraitButton = ContainerFrame1PortraitButton {
  49.  }
  50.  Portrait = ContainerFrame1Portrait {
  51.  }
  52.  ClickableTitleFrame = <unnamed> {
  53.  }
  54.  bags = <table> {
  55.  }
  56.  FilterDropDown = ContainerFrame1FilterDropDown {
  57.  }
  58.  bagsShown = 1
  59.  FilterIcon = <unnamed> {
  60.  }
  61.  allBags = true
  62.  size = 16
  63. }
  64.  = <function> defined =[C]:-1
  65.  = <function> defined @GearHelper\GearHelper.lua:540







Thanks

Last edited by Marsgames : 11-21-17 at 01:11 PM.
  Reply With Quote
11-21-17, 03:49 PM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
The poseDot function is called every time you open your bag? Then you are adding an additional hook on ContainerFrame_Update each time you open your bag.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
11-22-17, 01:27 PM   #3
Marsgames
An Aku'mai Servant
 
Marsgames's Avatar
Join Date: Jul 2016
Posts: 33
Arrow Fix C Stack Overflow overlay

Ok, for those who have same issue when creating overlay, I fixed it with this code

Lua Code:
  1. function poseDot()
  2.     for bag = 0,4 do
  3.         for slot = 1, GetContainerNumSlots(bag) do
  4.  
  5.             local myBag = bag+1
  6.             local mySlot = GetContainerNumSlots(bag) - (slot - 1)
  7.             local button = _G["ContainerFrame"..myBag.."Item"..mySlot]
  8.  
  9.             if button.overlay then
  10.                 button.overlay:SetShown(false)
  11.                 button.overlay = nil
  12.             end
  13.  
  14.             local itemLink = GetContainerItemLink(bag, slot)
  15.             if itemLink then
  16.  
  17.                 local weightCalcResult = weightCalculation(itemLink)
  18.                 if weightCalcResult[1] ~= nil and weightCalcResult[1] > 0 or weightCalcResult[2] ~= nil and weightCalcResult[2] > 0 then
  19.  
  20.                     -- create overlay texture if it doesn't exit for the button
  21.                     if not button.overlay then
  22.                         button.overlay = button:CreateTexture(nil,"OVERLAY")
  23.                         button.overlay:SetSize(18,18)
  24.                         button.overlay:SetPoint("TOPLEFT")
  25.                         button.overlay:SetTexture("Interface\\AddOns\\GearHelper\\Textures\\flecheUp")
  26.                         --button.overlay:SetTexture("Interface\\Common\\Indicator-Green")
  27.                         button.overlay:SetShown(true)
  28.                     end
  29.                 end
  30.  
  31.             end
  32.  
  33.         end
  34.     end
  35.     ContainerFrame_UpdateAll()
  36. end

and I call my function in
function allEvents:ITEM_PUSH( bag, icone )
and
function allEvents:BAG_UPDATE( bagID )
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » 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