42 - Add an OnRelease argument to :SetAutoHideDelay

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:SetAutoHideDelay(0.25, self)
	DisplayTooltip() -- Tooltip population function

function addon:Hide()
      if addon.tooltip then
        addon.tooltip = nil

This works in isolated testing, but will break when other addons are using library and you get a call sequence like:

  < 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.

User When Change
Torhal Feb 04, 2015 at 01:01 UTC Changed status from New to Fixed
oscarucb Nov 10, 2013 at 07:55 UTC Create

You must login to post a comment. Don't have an account? Register to get one!

  • 1 comment
  • Avatar of Torhal Torhal Feb 04, 2015 at 01:01 UTC - 0 likes

    No idea how I missed this ticket.

  • 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.

Reported by

Possible assignees