As currently designed, lib:SetAutoHideDelay( ) is a subtly dangerous feature, because the timer can release the tooltip without running any addon code. This can be a problem if the addon is left holding a reference to the dead tooltip in a variable. If the addon later tries to manipulate this variable it can silently corrupt some other addon's tooltip.
I've seen at least three separate addons (written by different authors) do something like this:
function addon:Show() addon.tooltip = LibStub('LibQTip-1.0'):Acquire('MyFooBarTooltip', 5, "LEFT", "CENTER") addon.tooltip:SmartAnchorTo(self) addon.tooltip:SetAutoHideDelay(0.25, self) DisplayTooltip() -- Tooltip population function end function addon:Hide() if addon.tooltip then addon.tooltip:Release() addon.tooltip = nil end end
This works in isolated testing, but will break when other addons are using library and you get a call sequence like:
addon:Show() < auto-hide > < some other addon calls Acquire() > addon:Hide() -- this Release will stomp on the tooltip belonging to the other addon
There are several possible fixes, the easiest being to use the undocumented OnRelease handler:
addon.tooltip:SetAutoHideDelay(0.25, self) + addon.tooltip:OnRelease = function() addon.tooltip = nil end -- runs on auto-hide
It would be a better design to add a third optional argument to lib:SetAutoHideDelay(), an optional function to be called upon tooltip release. This would have the same effect as the currently undocumented OnRelease field, but by placing it in the official API it becomes a documented feature and improves the chances that clients of this method will notice the potential for danger and use it correctly, eg:
addon.tooltip:SetAutoHideDelay(0.25, self, function() addon.tooltip = nil end)
This improvement can be made without changing the library major version, because it only extends the API in a backward-compatible manner (should still increment the minor version number to indicate the new feature). Estimated implementation and documentation effort: 5 minutes.
- 1 comment
- Last updated
- Feb 04, 2015
- Nov 10, 2013
- Fixed - Developer made requested changes. QA should verify.
- Enhancement - A change which is intended to better the project in some way
- Medium - Normal priority.