Quantcast

BUg fixes and memory leaks.

Scott Sibley [09-14-10 - 06:48]
BUg fixes and memory leaks.
You should be able to modify and add new widgets now.
Filename
Modules/Bars.lua
Modules/Debug.lua
Modules/Histograms.lua
Modules/Text.lua
Modules/UnitTooltip.lua
diff --git a/Modules/Bars.lua b/Modules/Bars.lua
index 1cadc53..e2b0dd3 100644
--- a/Modules/Bars.lua
+++ b/Modules/Bars.lua
@@ -309,21 +309,13 @@ function mod:OnInitialize()
 end

 function mod:OnEnable()
-	if not self.bars then self.bars = {} end
-
-	for k, bar in pairs(self.bars) do
-		bar.bar:Hide()
-	end
-	createBars()
+	self:ClearBars()
 	GameTooltip:SetClampRectInsets(0, 0, 10, 10)
 	StarTip:SetOptionsDisabled(options, false)
 end

 function mod:OnDisable()
-	for k, bar in pairs(self.bars) do
-		bar:Del()
-		bar.bar:Hide()
-	end
+	self:ClearBars()
 	GameTooltip:SetClampRectInsets(0, 0, 0, 0)
 	StarTip:SetOptionsDisabled(options, true)
 end
diff --git a/Modules/Debug.lua b/Modules/Debug.lua
index 6680802..11e3bc3 100644
--- a/Modules/Debug.lua
+++ b/Modules/Debug.lua
@@ -24,7 +24,7 @@ return '--' .. select(1, UnitName(unit)) .. '--'
 if not UnitExists(unit) then return end
 return ClassColor(unit)
 ]],
-		cols = 50,
+		cols = 500,
 		align = WidgetText.ALIGN_PINGPONG,
 		update = 1000,
 		speed = 100,
@@ -54,21 +54,30 @@ local function new3()
 	return LibProperty:New(nil, core,	"debug property", "", "")
 end

+local plugin = {}
+LibStub("StarLibPluginString-1.0"):New(plugin)

 local function update()
+	do return end
 	for i, v in ipairs(objects) do
 		v:Del()
 	end
 	wipe(objects)
-	for j = 1, random(10) do
+	ResourceServer.Update()
+	local mem1, percent1, memdiff1, totalMem1, totaldiff1 = ResourceServer.GetMemUsage("StarTip")
+	for j = 1, random(50) do
 		local object = new2()
+		object.cols = random(50)
+		object:Start()
 		tinsert(objects, object)
 	end
-	StarTip:Print(#objects)
+	ResourceServer.Update()
+	local mem2, percent2, memdiff2, totalMem2, totaldiff2 = ResourceServer.GetMemUsage("StarTip")
+	StarTip:Print("Memory",  plugin.memshort(mem2 - mem1), plugin.memshort(memdiff2))
 end

 function mod:OnEnable()
-	timer = timer or LibTimer:New("Debug timer", 100, true, update)
+	timer = timer or LibTimer:New("Debug timer", 1000, true, update)
 	timer:Start()
 end

diff --git a/Modules/Histograms.lua b/Modules/Histograms.lua
index 8e251b9..2dc8c89 100644
--- a/Modules/Histograms.lua
+++ b/Modules/Histograms.lua
@@ -87,7 +87,7 @@ return PowerColor("RAGE", unit)
 		name = "Mem",
 		type = "histogram",
 		expression = [[
-mem, percent, memdiff, totalMem, totaldiff = GetMemUsage("StarTip")
+local mem, percent, memdiff, totalMem, totaldiff = GetMemUsage("StarTip")

 if mem then
     if totaldiff == 0 then totaldiff = 1 end
@@ -370,19 +370,14 @@ function mod:OnInitialize()
 end

 function mod:OnEnable()
-	if not self.histograms then self.histograms = {} end
-
+	self:ClearHistograms()
+	createHistograms()
 	GameTooltip:SetClampRectInsets(0, 0, 10, 10)
 	StarTip:SetOptionsDisabled(options, false)
 end

 function mod:OnDisable()
-	for k, widget in pairs(self.histograms) do
-		widget.bars:Del()
-		for i = 1, #widget.bars do
-			widget.bars[i]:Hide()
-		end
-	end
+	self:ClearHistograms()
 	GameTooltip:SetClampRectInsets(0, 0, 0, 0)
 	StarTip:SetOptionsDisabled(options, true)
 end
diff --git a/Modules/Text.lua b/Modules/Text.lua
index cd79a8f..051583c 100644
--- a/Modules/Text.lua
+++ b/Modules/Text.lua
@@ -113,7 +113,7 @@ return HPColor(mana, max)
 		parent = "GameTooltip"
 	},
 	[4] = {
-		name = "Memory",
+		name = "Memory Percent",
 		enabled = false,
 		value = [[
 local mem, percent, memdiff, totalMem, totaldiff = GetMemUsage("StarTip")
@@ -147,7 +147,30 @@ end
 		parent = "GameTooltip"
 	},
 	[5] = {
-		name = "CPU",
+		name = "Memory Total",
+		enabled = false,
+		value = [[
+local mem, percent, memdiff, totalMem, totaldiff = GetMemUsage("StarTip")
+if mem then
+    if totaldiff == 0 then totaldiff = 1 end
+    memperc = (mem / totalMem * 100)
+    local num = floor(memperc + 0.5)
+    if num < 1 then num = 1 end
+    if num > 100 then num = 100 end
+    return format("%s (%.2f%%)", memshort(mem), memperc)
+end
+]],
+		color = [[
+return 1, 1, 0
+]],
+		cols = 10,
+		update = 1000,
+		dontRtrim = true,
+		point = {"TOPLEFT", "GameTooltip", "BOTTOMLEFT", 0, -124},
+		parent = "GameTooltip"
+	},
+	[6] = {
+		name = "CPU Percent",
 		enabled = false,
 		value = [[
 local cpu, percent, cpudiff, totalCPU, totaldiff = GetCPUUsage("StarTip")
@@ -180,6 +203,27 @@ end
 		point = {"TOPRIGHT", "GameTooltip", "BOTTOMRIGHT", 0, -62},
 		parent = "GameTooltip"
 	},
+	[7] = {
+		name = "CPU Total",
+		enabled = false,
+		value = [[
+local cpu, percent, cpudiff, totalCPU, totaldiff = GetCPUUsage("StarTip")
+if cpu then
+    if totalCPU == 0 then totalCPU = 100 end
+    cpuperc = cpu / totalCPU * 100;
+    return format("%s (%.2f%%)", timeshort(cpu), cpuperc)
+end
+]],
+		color = [[
+return 1, 1, 0
+]],
+		cols = 10,
+		align = WidgetText.ALIGN_RIGHT,
+		update = 1000,
+		dontRtrim = true,
+		point = {"TOPRIGHT", "GameTooltip", "BOTTOMRIGHT", 0, -124},
+		parent = "GameTooltip"
+	},
 }

 local defaults = {
@@ -319,14 +363,7 @@ function mod:OnInitialize()
 	if not self.db.profile.texts then
 		self.db.profile.texts = {}
 	end
-
-	for k in pairs(self.db.profile.texts) do
-		if type(k) == "string" then
-			wipe(self.db.profile.texts)
-			break
-		end
-	end
-
+
 	for i, v in ipairs(defaultWidgets) do
 		for j, vv in ipairs(self.db.profile.texts) do
 			if v.name == vv.name and not vv.custom then
@@ -354,21 +391,14 @@ function mod:OnInitialize()
 end

 function mod:OnEnable()
-	if not self.texts then self.texts = {} end
-
-	for k, text in pairs(self.texts) do
-		text.text:Hide()
-	end
+	self:ClearTexts()
 	createTexts()
 	GameTooltip:SetClampRectInsets(0, 0, 10, 10)
 	StarTip:SetOptionsDisabled(options, false)
 end

 function mod:OnDisable()
-	for k, text in pairs(self.texts) do
-		text:Del()
-		text.text:Hide()
-	end
+	self:ClearTexts()
 	GameTooltip:SetClampRectInsets(0, 0, 0, 0)
 	StarTip:SetOptionsDisabled(options, true)
 end
diff --git a/Modules/UnitTooltip.lua b/Modules/UnitTooltip.lua
index 0e494db..40fcc8d 100644
--- a/Modules/UnitTooltip.lua
+++ b/Modules/UnitTooltip.lua
@@ -430,7 +430,7 @@ end

 local widgetsToDraw = {}
 local function updateWidget(widget)
-	widgetsToDraw[widget] = true
+	tinsert(widgetsToDraw, widget)
 	if mod.db.profile.refreshRate == 0 then
 		draw()
 	end
@@ -440,7 +440,7 @@ do
 	local fontsList = LSM:List("font")
 	local widget, fontString
 	function draw()
-		for widget in pairs(widgetsToDraw) do
+		for i, widget in ipairs(widgetsToDraw) do
 			if not widget.fontString then break end
 			local fontString = widget.fontString
 			fontString:SetText(widget.buffer)
@@ -467,6 +467,12 @@ do
 	end
 end

+--@debug@
+local PluginResources = ResourceServer or LibStub("StarLibPluginResourceTools-1.0")
+local plugin = {}
+LibStub("StarLibPluginString-1.0"):New(plugin)
+--@end-debug@
+
 local tbl
 function mod:CreateLines()
     local llines = {}
@@ -478,8 +484,11 @@ function mod:CreateLines()
 			llines[j].config = copy(v)
 		end
     end
-    lines = setmetatable(llines, {__call=function(self)
-
+    lines = setmetatable(llines, {__call=function(self)
+		--@debug@
+		PluginResources.Update()
+		local mem, percent, memdiff, totalMem, totaldiff = PluginResources.GetMemUsage("StarTip")
+		--@end-debug@
         local lineNum = 0
 		GameTooltip:ClearLines()
         for i, v in ipairs(self) do
@@ -494,14 +503,13 @@ function mod:CreateLines()
                     right = ''
                     left = mod.evaluator.ExecuteCode(environment, v.name .. " left", v.left)
                 end
-
+
                 if left and left ~= "" and right ~= "nil" then
                     lineNum = lineNum + 1
                     if v.right then
 						GameTooltip:AddDoubleLine(' ', ' ', mod.db.profile.color.r, mod.db.profile.color.g, mod.db.profile.color.b, mod.db.profile.color.r, mod.db.profile.color.g, mod.db.profile.color.b)

 						if not v.leftObj or v.lineNum ~= lineNum then
-							--if v.leftObj then v.leftObj:Del() end
 							v.config.value = v.left
 							local tmp = v.update
 							if not v.leftUpdating then v.update = 0 end
@@ -510,7 +518,6 @@ function mod:CreateLines()
 						end

 						if not v.rightObj or v.lineNum ~= lineNum then
-							--if v.rightObj then v.rightObj:Del() end
 							v.config.value = v.right
 							local tmp = v.update
 							if not v.rightUpdating then v.update = 0 end
@@ -518,9 +525,7 @@ function mod:CreateLines()
 							v.update = tmp
 						end
 						v.leftObj.fontString = mod.leftLines[lineNum]
-						widgetsToDraw[v.leftObj] = true
 						v.rightObj.fontString = mod.rightLines[lineNum]
-						widgetsToDraw[v.rightObj] = true
                     else
 						GameTooltip:AddLine(' ', mod.db.profile.color.r, mod.db.profile.color.g, mod.db.profile.color.b)

@@ -530,23 +535,12 @@ function mod:CreateLines()
 						v.leftObj = v.leftObj or WidgetText:New(mod.core, v.name, copy(v.config), 0, 0, 0, StarTip.db.profile.errorLevel, updateWidget)
 						v.update = tmp
 						v.leftObj.fontString = mod.leftLines[lineNum]
-						widgetsToDraw[v.leftObj] = true
                     end
 					if v.rightObj then
-						if mod.db.profile.refreshRate == 0 then
-							v.rightObj.update = 0
-							v.rightObj.speed = 0
-							v.rightObj:Init()
-						end
 						v.rightObj.config.unit = StarTip.unit
 						v.rightObj:Start()
 					end
 					if v.leftObj then
-						if mod.db.profile.refreshRate == 0 then
-							v.leftObj.update = 0
-							v.leftObj.speed = 0
-							v.leftObj:Init()
-						end
 						v.leftObj.config.unit = StarTip.unit
 						v.leftObj:Start()
 					end
@@ -555,8 +549,14 @@ function mod:CreateLines()
 			end

         end
-        --mod.NUM_LINES = lineNum
-	GameTooltip:Show()
+        mod.NUM_LINES = lineNum
+		--@debug@
+		PluginResources.Update()
+		local mem2, percent2, memdiff2, totalMem2, totaldiff2 = PluginResources.GetMemUsage("StarTip")
+		--StarTip:Print("Memory: ", plugin.memshort(mem2 - mem))
+		--@end-debug@
+		draw()
+		GameTooltip:Show()
     end})
 end