Reply
Thread Tools Display Modes
Unread 01-27-13, 01:50 AM   #1
Brusalk
A Fallenroot Satyr
 
Brusalk's Avatar
AddOn Author - Click to view addons
Join Date: May 2010
Posts: 29
texture obj gets cleared but set attributes stay in table

Hi there!

I have a perplexing problem. I have a local table, textures, which is indexed by the texture object/widget. The value at a given index is true if the texture is in use, and false if not. (to store previously created textures to save work)

Now the perplexing part is that somewhere the texture is losing it's classification or whatever as a widget. However, any manually set values inside the widgets table stay. I have absolutely no clue what's causing this to happen and I was wondering if anyone else has had this happen to them.

Below is my get and free texture functions.

Code:
local numTexs = 0
function ns:getTempTexture(parent)
	local texture
	
	for tex, used in pairs(textures) do
		if not texture and not used then
			texture = tex
			textures[texture] = true
			--print("Gave premade texture ", texture.name)
			break
		end
	end
	
	if not texture then -- need to make one
		texture = ns.frame:CreateTexture("Texture"..(numTexs))
		texture.name = "Texture"..(numTexs)
		textures[texture] = true
		--print("Made new texture ", texture.name)
	end
	
	numTexs = numTexs + 1
	texture:Hide()
	texture:SetParent(parent or ns.frame)
	
	return texture	
end

function ns:freeTempTexture(texture)
	
	if texture == nil then return end

	if textures[texture] then -- in use
		textures[texture] = false -- Free the texture up
		--print("Freed up texture ", texture.name)
		texture:Hide() -- Hide it.
		texture:ClearAllPoints() -- Unset it's location settings
		return
	end
	
	print("Attempting to remove a non used texture?")	
end
Now to be more specific, if I do a /dump on the textures table after a few textures have already been created, I get something like
Code:
textures = {
[Texture:Texture0] = false,
[Texture:Texture1] = false,
[Texture:Texture2] = false,
}
which is perfectly fine. However, when I call getTempTexture() after this point, I get an error that Hide() can't be performed on a non-widget. When I then dump out the textures table again, instead I get

Code:
textures = {
[{name="Texture0"}] = false,
[Texture:Texture1] = false,
[Texture:Texture2] = false,
}
Something is causing the object to lose it's texture properties but keep set values in the table, and I have absolutely no clue what it is.

Thoughts? Thanks!
Brusalk is offline   Reply With Quote
Unread 01-27-13, 02:27 AM   #2
Phanx
A Pyroguard Emberseer
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 4,253
Post your entire code. Attach files to your post, or use a paste site.
__________________
Author/maintainer of Grid, PhanxChat, ShieldsUp, 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!
Phanx is offline   Reply With Quote
Unread 01-27-13, 02:51 AM   #3
Brusalk
A Fallenroot Satyr
 
Brusalk's Avatar
AddOn Author - Click to view addons
Join Date: May 2010
Posts: 29
The whole file is attached.

Whole addon with problem: https://github.com/Brusalk/EventHorizon-2.0


The problem specifically happens when the following 2 commands are run allowing time for the bar to fall off the left side of the spellbar before calling the 2nd one.

/run EH:addTimedBar("core", EH.spellbars.active[1], 9, 1, "cooldown", 3, "debuff")

and then

/run EH:addTimedBar("core", EH.spellbars.active[1], 9, 1, "cooldown", 3, "debuff")

after 12 seconds.

The second /run will error the following:

Code:
3x EventHorizon\EventHorizon-2.0.0.lua:585: Attempt to find "this" in non-framescript object
<in C code>
EventHorizon\EventHorizon-2.0.0.lua:585: in function "getTempTexture"
EventHorizon\EventHorizon-2.0.0.lua:748: in function "addTimedBar"
<string>:"EH:addTimedBar("core", EH.spellbars.active[ChatFrame.lua:2158: in function "?"
FrameXML\ChatFrame.lua:4388: in function <FrameXML\ChatFrame.lua:4334>
<in C code>
FrameXML\ChatFrame.lua:4082: in function "ChatEdit_SendText"
FrameXML\ChatFrame.lua:4121: in function "ChatEdit_OnEnterPressed"
[string "*:OnEnterPressed":1: in function <string>:"*:OnEnterPressed":1

Locals:
self = <table> {
 blendModes = <table> {}
 layouts = <table> {}
 updateSettings = <func> @..\EventHorizon.lua:1119
 modules = <table> {}
 InitializeClass = <func> @EventHorizon_Warlock\config.lua:1
 textures = <table> {}
 freeTempTexture = <func> @..\EventHorizon.lua:590
 isModuleEnabled = <func> @..\EventHorizon.lua:288
 addSpellbarConfig = <func> @..\EventHorizon.lua:424
 spellbarConfig = <table> {}
 test = <table> {}
 nowLine = <unnamed> {}
 updateSpellbarSettings = <func> @..\EventHorizon.lua:973
 registerModuleEvent = <func> @..\EventHorizon.lua:295
 addTimedBar = <func> @..\EventHorizon.lua:655
 addBlendMode = <func> @..\EventHorizon.lua:382
 getSpellbarConfig = <func> @..\EventHorizon.lua:487
 getColor = <func> @..\EventHorizon.lua:457
 defaultConfig = <table> {}
 removeTimedBar = <func> @..\EventHorizon.lua:845
 getLayout = <func> @..\EventHorizon.lua:475
 getPositionByNow = <func> @..\EventHorizon.lua:885
 config = <table> {}
 events = <table> {}
 frame = <unnamed> {}
 getSavedVariable = <func> @..\EventHorizon.lua:543
 hookSpellbarHide = <func> @..\EventHorizon.lua:512
 addError = <func> @..\EventHorizon.lua:108
 addSpellbarRequirement = <func> @..\EventHorizon.lua:437
 shown = true
 getTempStatusBar = <func> @..\EventHorizon.lua:611
 getPositionByTime = <func> @..\EventHorizon.lua:877
 freeTempStatusBar = <func> @..\EventHorizon.lua:632
 getSavedVariablePerCharacter = <func> @..\EventHorizon.lua:560
 unregisterModuleEvent = <func> @..\EventHorizon.lua:336
 getConfig = <func> @..\EventHorizon.lua:483
 hookSpellbarSettingsUpdate = <func> @..\EventHorizon.lua:520
 barAnchor = <unnamed> {}
 defaultLayouts = <table> {}
 checkRequirements = <func> @..\EventHorizon.lua:1092
 hookSpellbarShow = <func> @..\EventHorizon.lua:503
 cBlendModes = <table> {}
 addConfig = <func> @..\EventHorizon.lua:410
 error = <func> @..\EventHorizon.lua:99
 hookSpellbarCreation = <func> @..\EventHorizon.lua:495
 applySettings = <func> @..\EventHorizon.lua:1191
 updateTimedBar = <func> @..\EventHorizon.lua:840
 statusbars = <table> {}
 defaultColors = <table> {}
 updateSpellbarIcon = <func> @..\EventHorizon.lua:1036
 getTempTexture = <func> @..\EventHorizon.lua:569
 cConfig = <table> {}
 getBlendMode = <func> @..\EventHorizon.lua:471
 defaultBlendModes = <table> {}
 removeSpellUpdate = <func> @..\EventHorizon.lua:865
 getIconForSpellbar = <func> @..\EventHorizon.lua:1072
 addSpellUpdate = <func> @..\EventHorizon.lua:851
 addColor = <func> @..\EventHorizon.lua:368
 enableModule = <func> @EventHo
Attached Files
File Type: lua EventHorizon.lua (57.8 KB, 169 views)
Brusalk is offline   Reply With Quote
Unread 01-27-13, 06:09 AM   #4
Phanx
A Pyroguard Emberseer
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 4,253
Well, that error is certainly interesting, because it names line 585, which is a blank line in the file you posted...

Anyway, I don't see anything immediately obvious, and don't have time right now to comb through everything to figure out what's going wrong, but I'd suggest using a more robust recycling system for your textures.

Code:
local textures = {} -- textures in use

local GetTexture, FreeTexture
do
	local pool = {}
	function GetTexture(parent)
		local texture = next(pool)
		if texture then
			pool[texture] = nil
			texture:SetParent(texture)
			return texture
		else
			return parent:CreateTexture()
		end
	end
	function FreeTexture(texture)
		texture:ClearAllPoints()
		texture:SetParent(nil) -- might need to use UIParent instead of nil here
		texture:SetTexture(nil)
		pool[texture] = true
	end
end
Mixing used and unused textures in the same table seems like a recipe for trouble.

Also, when you clear the texture, don't forget to nil out the reference to it, eg:

Code:
bar.segments[firstVisible].tick = ns:freeTempTexture(bar.segments[firstVisible].tick)
I didn't look very far, but this may be related to your problem.
__________________
Author/maintainer of Grid, PhanxChat, ShieldsUp, 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!

Last edited by Phanx : 01-27-13 at 10:19 PM.
Phanx is offline   Reply With Quote
Unread 01-27-13, 05:42 PM   #5
Brusalk
A Fallenroot Satyr
 
Brusalk's Avatar
AddOn Author - Click to view addons
Join Date: May 2010
Posts: 29
Looks like it was a problem with the getTempTexture function.

Your code works perfectly. Thanks!
Brusalk is offline   Reply With Quote
Unread 01-27-13, 10:20 PM   #6
Phanx
A Pyroguard Emberseer
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 4,253
I edited my previous code slightly to set the parent in the GetTexture function, so it's consistent between the pooled and newly created textures returned.
__________________
Author/maintainer of Grid, PhanxChat, ShieldsUp, 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!
Phanx is offline   Reply With Quote
Unread 01-27-13, 11:30 PM   #7
Brusalk
A Fallenroot Satyr
 
Brusalk's Avatar
AddOn Author - Click to view addons
Join Date: May 2010
Posts: 29
I have a somewhat related problem I think.

I'm getting the textures and everything is fine and dandy. The first time that I call EH:addTimedBar() the tick indicators are shown above the background texture correctly, however from then on the tick indicators show behind it, even though I've used tick:SetDrawLayer() and set them on completely different levels.

I've been trying to figure out why the ticks are showing behind textures that they should be in front of, but it's been a few hours now with no luck.

Do you have much experience with trying to draw stuff on different layers to ensure something is always right where it should be?

I thought the problem might be related to not sharing the same parent with the other textures, but even if they share it I still have the same issue.

Thanks.

-Brusalk
Brusalk is offline   Reply With Quote
Unread 01-27-13, 11:43 PM   #8
Brusalk
A Fallenroot Satyr
 
Brusalk's Avatar
AddOn Author - Click to view addons
Join Date: May 2010
Posts: 29
https://github.com/Brusalk/EventHori...r/EventHorizon

link to current branch with most up-to-date code.
Brusalk is offline   Reply With Quote
Reply

Go BackWoWInterface » Developer Discussions » Lua/XML Help » texture obj gets cleared but set attributes stay in table

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