Thread Tools Display Modes
05/11/14, 05:12 AM   #1
Nogaruk
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 15
Too many anchors - options menu

Hello,
I know there's already a similar thread to this one, but it did not seem to be the same issue and I do not want to hijack their thread.

I started working on my options panel and today I ran across this error - UI Error - "Too many anchors processed." That is all it says. No reference to how it got to that point. I sometimes get another one talking about a child out of range with Fit Descendants. It does not happen all the time and I've changed my code multiple times, so I do not have the exact wording of it anymore. The 2nd error could potentially have been from a code change as well, but figure I'd mention it just in case it helps.

Now, the anchor error only happens when I actually select my options panel and thus make it visible. So, as far as I can tell, the creation of the options panel is what is causing it. The only addons I have turned on is the one I'm working on and zgoo. I only have 2 headers, a checkbox with a label, a slider with a label, and 1 color picker being created at the moment. I had 5 color picker's which were successfully being created prior to this error happening, but I turned them off for now.

This started when I changed my checkbox creation (which is the 2nd object created, the first being a header or section title) from:

Code:
function _NST:CreateOptionsCheckbox()
        NST.optionsWindow.testCheckbox = WM:CreateControlFromVirtual("NST_TEST_CHECKBOX", ZO_OptionsWindowSettingsScrollChild, "ZO_Options_Checkbox")
	NST.optionsWindow.testCheckbox:ClearAnchors()
	NST.optionsWindow.testCheckbox:SetAnchor(TOPLEFT,NST.optionsWindow.header,BOTTOMLEFT, 0, 6)
	NST.optionsWindow.testCheckbox.controlType = OPTIONS_CHECKBOX
	NST.optionsWindow.testCheckbox.system = SETTING_TYPE_UI
	NST.optionsWindow.testCheckbox.settingId = _G[string.format("SETTING_NST_TEST_CHECKBOX")]
	NST.optionsWindow.testCheckbox.panel = _G["NST_OPTIONS_WINDOW"]
	NST.optionsWindow.testCheckbox.text = "Test Layout"
	NST.optionsWindow.testCheckbox.tooltipText = "Test text"
			
	NST.optionsWindow.testCheckbox.button = NST.optionsWindow.testCheckbox:GetNamedChild("Checkbox")
			
	--	Set saved variable OnClicked
	ZO_PreHookHandler(NST.optionsWindow.testCheckbox.button, "OnClicked", function() self:SetTestCheckbox() end)
			
	--	Warning icon and tooltip to show a reload is needed for this setting 
	NST.optionsWindow.testCheckbox.warning = WM:CreateControlFromVirtual("NST_TEST_CHECKBOX_WARNING", NST.optionsWindow.testCheckbox, "ZO_Options_WarningIcon")
	NST.optionsWindow.testCheckbox.warning:SetAnchor(RIGHT, NST.optionsWindow.testCheckbox.button, LEFT, -5, 0)
	NST.optionsWindow.testCheckbox.warning.tooltipText = "You need to reload the UI after changing this option"
			
	--	Shows the final control
	ZO_OptionsWindow_InitializeControl(NST.optionsWindow.testCheckbox)
end
to a creation function so I could make multiples easier:

Code:
function _NST:CreateOptionsCheckbox()
	NST.optionsWindow.goldCheckbox = self:CreateControlCheckbox("NST_Options_Checkbox_Gold",NST.optionsWindow.header,"Gold Carried","Sets the gold carried window to active or disabled",nil,nil,true,"You need to reload the UI after changing this option")
end
Code:
function _NST:CreateControlCheckbox(controlName,controlParent,text,tooltipText,getFunc,setFunc,warning,warningText)
	local checkbox = WM:CreateControlFromVirtual(controlName,ZO_OptionsWindowSettingsScrollChild, "ZO_Options_Checkbox")
	checkbox:ClearAnchors()
	checkbox:SetAnchor(TOPLEFT,controlParent,BOTTOMLEFT,0,6)
	checkbox.controlType = OPTIONS_CHECKBOX
	checkbox.system = SETTING_TYPE_UI
	checkbox.settingId = _G[string.format("SETTING_%s",controlName)]
	checkbox.panel = _G["NST_OPTIONS_WINDOW"]
	checkbox.text = text
	checkbox.tooltipText = tooltipText
			
	checkbox.button = checkbox:GetNamedChild("Checkbox")
			
	--	Set saved variable OnClicked
	ZO_PreHookHandler(checkbox.button, "OnClicked", function() self:SetTestCheckbox() end)
			
	--	Warning icon and tooltip to show a reload is needed for this setting 
	if warning then
		checkbox.warning = WM:CreateControlFromVirtual(controlName.."WarningIcon",checkbox,"ZO_Options_WarningIcon")
		checkbox.warning:ClearAnchors()
		checkbox.warning:SetAnchor(RIGHT,checkbox.button,LEFT,-5,0)
		checkbox.warning.tooltipText = warningText
	end
			
	--	Shows the final control
	ZO_OptionsWindow_InitializeControl(checkbox)
			
	return checkbox
end
From the research I have done so far I have not managed to find a real answer to this problem. Hopefully we can get a more detailed analysis of what is actually happening as well and even put it on the wiki for better practices. Setting up an options panel is not really discussed there yet.

What I have garnered so far is that anchor processing errors from one of two things;
1) You actually hit the anchor creation cap
2) Too many child chaining of anchors occurs

From point 1) I think I can be fairly safe in saying that it is not the problem. The cap should be fairly high, even running at minimum settings, that so few options should create it. Even without counting, I should only have at most 20 anchors. The cap should be well over 100 if not 1k. Though, I could be wrong.

So this leaves me with option 2). I am chaining Panel control -> Header -> containerA -> containerB -> Header 2 -> containerC.

So is it that I need to parent everything to the Panel and use offsets for placement because the "Tree" is becoming too deep?

Does anyone know how deep in the Tree you can go before this error would happen?

What am I missing that this would happen simply by changing from having static code to a re-usable function?

I use ClearAnchors() prior to using SetAnchor throughout my entire project, though I likely don't need to in the options section since I should be creating these controls without them having any anchors associated to them previously, but I tend to do it anyway. I have tried it without using ClearAnchors and I still get the error, which is what I would expect to happen.

If there's a better way to create an options panel that will prevent this from happening I would love to be pointed in the right direction. Right now I am just flummoxed as to why putting this into a function would even cause it to happen. Is it processing the anchors twice because I'm creating the anchors in the function to a local variable and then the engine is processing them again when I set a new variable to the return? If so, how would you work around this so that you do not have to manually set those 18+ lines of code for every single checkbox you would want to make?

Alot of questions, I know. If you've read this far, I really appreciate it and thank you. Thank you ahead of time for anyone that can shed some light on any of this, as well.

Last edited by Nogaruk : 05/11/14 at 05:17 AM.
  Reply With Quote
05/11/14, 11:51 AM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 648
I would really appreciate it if you did not copy-paste code from LibAddonMenu. It is under copyright, after all.
  Reply With Quote
05/11/14, 01:35 PM   #3
Nogaruk
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 15
I'm sorry if it is almost a copy at the moment, lam does have other handlers which my copy does not, but I was planning on adding more changes inside of the call. I only meant to use it as a reference to get started.

If that would still be too close for you, I'll drop it entirely. However, even if I was calling lam directly instead of just adding the one function rather than the whole library, I would still have the same issue.
  Reply With Quote
05/11/14, 05:56 PM   #4
Nogaruk
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 15
So to help not step on toes further, I dropped creating from virtual completely and tried making my own checkbox rather than wait to revise the function I was going to reference from LAM. I have not finished it completely as I still need to work on the actual toggle portion, but the basic setup is:

Code:
function _NST:CreateControlButtonCheckbox(btnName,btnParent,btnText,btnSelfAlign,btnTargetAlign,btnOffsetX,btnOffsetY,btnDimX,btnDimY)
	local btnHolder = WM:CreateControl(btnName,btnParent,CT_BUTTON)
	btnHolder:SetText(btnText)
	btnHolder:SetFont(NST.font2)
		
	btnHolder:SetDisabledFontColor(50,50,50,1)
	btnHolder:SetDisabledPressedFontColor(75,75,75,1)
	btnHolder:SetMouseOverFontColor(150,150,150,1)
	btnHolder:SetNormalFontColor(200,200,200,1)
	btnHolder:SetPressedFontColor(255,255,255,1)
		
	btnHolder:SetDimensions(510,26)
	btnHolder:ClearAnchors()
	btnHolder:SetAnchor(btnSelfAlign,btnParent,btnTargetAlign,btnOffsetX,btnOffsetY)
		
	btnHolder:SetHandler("OnClicked", function(self) _NST:OnCheckboxClicked(btnHolder) end)
		
	btnHolder.checkbox = WM:CreateControl(btnName.."Checkbox",btnHolder,CT_CONTROL)
	btnHolder.checkbox:SetDimensions(24,24)
	btnHolder.checkbox:ClearAnchors()
	btnHolder.checkbox:SetAnchor(RIGHT,btnHolder,RIGHT,0,0)
	btnHolder.checkbox.bd = WM:CreateControlFromVirtual(btnName.."Checkbox_Backdrop",btnHolder.checkbox,"ZO_DefaultBackdrop")
		btnHolder.checkbox.bd:SetAnchorFill(btnHolder.checkbox)
		
	btnHolder.checkbox.bd:SetCenterColor(25,25,25,1)
		
	btnHolder.controlType = OPTIONS_CUSTOM
	btnHolder.panel = _G["NST_OPTIONS_WINDOW"]
	btnHolder.system = SETTING_TYPE_UI
	return btnHolder
end
Slight issues atm, I need to figure out how to align the label text of the button to the left side (horrizontal alignment doesn't help). The color changes for the font do not seem to be working (mouseover,pressed, etc).

I also still get the error fairly quickly. I have 1 header created from virtual ZO_Options_SectionTitle and 1 slider from ZO_Options_Slider. I still get the error for anchors processed with more than 2 checkbox's made.

I am parenting the header and the slider to the panel and the "box's" to the header and then offsetting them down manually.
  Reply With Quote
05/12/14, 03:56 AM   #5
Aicam
Join Date: Apr 2014
Posts: 16
try setting the text after you set all text related attributes. that solved my issues when playing with font options on buttons.
  Reply With Quote
05/12/14, 04:35 AM   #6
CatoTheElder
Join Date: May 2014
Posts: 44
Originally Posted by Seerah View Post
I would really appreciate it if you did not copy-paste code from LibAddonMenu. It is under copyright, after all.
I would really appreciate seeing that copyright. It is international too, right?

--
Nogaruk, I ran a diff-check on the two functions you provided. In the second function, the following line is added:

Lua Code:
  1. checkbox.warning:ClearAnchors() -- added
  2. --NST.optionsWindow.testCheckbox.warning:ClearAnchors() -- missing

However, I believe you said you tried it with, and without that line, is that correct?

I haven't run in to that error yet, so unfortunately I cannot provide you with a quick and easy answer. Have you tried adding some debugging statements to count how many times the function is called? I'm wondering if there are some extra function calls, resulting in controls being drawn directly on top of each other.

Let me know if you're still having trouble after that, and I can delve in to it deeper, if need be.

Cheers!
  Reply With Quote
05/12/14, 06:27 AM   #7
Vicster0
 
Vicster0's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 82
Originally Posted by CatoTheElder View Post
I would really appreciate seeing that copyright. It is international too, right?
Here's the wiki article on it: http://en.wikipedia.org/wiki/Software_copyright

Doesn't list it there but the UK's IPO also similarly states software as literary works: http://www.ipo.gov.uk/types/copy/c-a...c-literary.htm

As does the following US Code: 17 U.S. Code § 101

Not sure if that's what you were looking for, but it's at least a good place to start.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Too many anchors - options menu

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