Optimize minimap border creation and management
Refactor minimap border handling to reuse a single frame and prevent memory leaks. Ensure the border is hidden instead of destroyed when the module is disabled.
This commit is contained in:
+25
-2
@@ -17,9 +17,25 @@ module.enable = function(self)
|
|||||||
Minimap:SetHeight(size)
|
Minimap:SetHeight(size)
|
||||||
Minimap:SetPoint("CENTER", MinimapCluster, "TOP", 9, -98)
|
Minimap:SetPoint("CENTER", MinimapCluster, "TOP", 9, -98)
|
||||||
Minimap:SetMaskTexture("Interface\\BUTTONS\\WHITE8X8")
|
Minimap:SetMaskTexture("Interface\\BUTTONS\\WHITE8X8")
|
||||||
Minimap.border = CreateFrame("Frame", nil, Minimap)
|
|
||||||
|
-- IMPORTANT: enable() can be called multiple times (reload UI, toggling
|
||||||
|
-- the module in ShaguTweaks settings, expansion switch, etc). Without
|
||||||
|
-- reusing a single persistent frame, every call created a brand new
|
||||||
|
-- anonymous CreateFrame("Frame") parented to Minimap, and the old ones
|
||||||
|
-- were never released -- they kept piling up as orphaned children of
|
||||||
|
-- Minimap forever. That's a likely contributor to the minimap-related
|
||||||
|
-- crashes (addons like MinimapButtonFrame walk Minimap:GetChildren()
|
||||||
|
-- every second and can choke on the growing pile of stale frames).
|
||||||
|
-- We now store the border on the module and just reconfigure it if it
|
||||||
|
-- already exists, instead of creating a new frame.
|
||||||
|
if not self.border then
|
||||||
|
self.border = CreateFrame("Frame", nil, Minimap)
|
||||||
|
end
|
||||||
|
Minimap.border = self.border
|
||||||
|
|
||||||
Minimap.border:SetFrameStrata("BACKGROUND")
|
Minimap.border:SetFrameStrata("BACKGROUND")
|
||||||
Minimap.border:SetFrameLevel(1)
|
Minimap.border:SetFrameLevel(1)
|
||||||
|
Minimap.border:ClearAllPoints()
|
||||||
Minimap.border:SetPoint("TOPLEFT", Minimap, "TOPLEFT", -3, 3)
|
Minimap.border:SetPoint("TOPLEFT", Minimap, "TOPLEFT", -3, 3)
|
||||||
Minimap.border:SetPoint("BOTTOMRIGHT", Minimap, "BOTTOMRIGHT", 3, -3)
|
Minimap.border:SetPoint("BOTTOMRIGHT", Minimap, "BOTTOMRIGHT", 3, -3)
|
||||||
Minimap.border:SetBackdrop({
|
Minimap.border:SetBackdrop({
|
||||||
@@ -28,6 +44,7 @@ module.enable = function(self)
|
|||||||
insets = { left = 3, right = 3, top = 3, bottom = 3 }})
|
insets = { left = 3, right = 3, top = 3, bottom = 3 }})
|
||||||
Minimap.border:SetBackdropBorderColor(.9,.8,.5,1)
|
Minimap.border:SetBackdropBorderColor(.9,.8,.5,1)
|
||||||
Minimap.border:SetBackdropColor(.4,.4,.4,1)
|
Minimap.border:SetBackdropColor(.4,.4,.4,1)
|
||||||
|
Minimap.border:Show()
|
||||||
|
|
||||||
if _G.MinimapClock then
|
if _G.MinimapClock then
|
||||||
if not self.clockOriginalPoint then
|
if not self.clockOriginalPoint then
|
||||||
@@ -41,8 +58,14 @@ module.enable = function(self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
module.disable = function(self)
|
module.disable = function(self)
|
||||||
|
-- Hide instead of leaking: keep the frame alive but out of the way so a
|
||||||
|
-- future enable() can reuse it cleanly.
|
||||||
|
if self.border then
|
||||||
|
self.border:Hide()
|
||||||
|
end
|
||||||
|
|
||||||
if _G.MinimapClock and self.clockOriginalPoint then
|
if _G.MinimapClock and self.clockOriginalPoint then
|
||||||
MinimapClock:ClearAllPoints()
|
MinimapClock:ClearAllPoints()
|
||||||
MinimapClock:SetPoint(unpack(self.clockOriginalPoint))
|
MinimapClock:SetPoint(unpack(self.clockOriginalPoint))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user