Titan Panel [Mount]

7 - Mounting via other ways, and a race condition

Especially on my druid I have to mount using other ways than TPM quite often. A common scenario: if I first mount my Purple Netherdrake via TPM and then later mount my Winterspring Saber using an action bar button, then TPM would show me as riding my Purple Netherdrake. This patch fixes this by checking that, when the player is mounted, the cached mount is actually summoned; if not the currently summoned mount is determined.

When testing this patch I ran into a race condition (not reliably reproducible and, given consistent function returns from WoW, logically impossible) that can make the addon crash at login when you were already mounted. This patch addresses it by simply testing for nil just before using the value and falling back to 'not mounted'.

Also included is a simple de-duplication of the function call to GetCompanionInfo(...) when setting favourites.

Below follows the patch in unified diff format. Revisions are from my personal SVN repository, so you can ignore those.

Index: TitanMount.lua
===================================================================
--- TitanMount.lua    (revision 11)
+++ TitanMount.lua    (revision 12)
@@ -76,11 +76,16 @@
     -- If mountNumber and mountSpell don't exist, mountNumber is updated to reflect the companion
     -- referenced in mountSpell, unless mountSpell is nil in which case that is updated.
     function GetMountInfo()
-        local name, icon, spell
+        local name, icon, spell, summoned
         if mountNumber == nil then
             return nil, nil
         end
-        _, name, spell, icon = GetCompanionInfo(MountID, mountNumber)
+        _, name, spell, icon, summoned = GetCompanionInfo(MountID, mountNumber)
+        if IsMounted() and not summoned then
+            -- Detects cache miss: we cached a mounted mount, but we're mounted on a different one...
+            -- Solution: determine currently mounted mount and update cache
+            return GetCurrentMount()
+        end
         if spell ~= mountSpell then
             if mountSpell == nil then
                 mountSpell = spell
@@ -138,6 +143,11 @@
             -- Mounted, but not cached
             else mountName, mountIcon = GetCurrentMount()
     end
+    -- There seems to be a race condition in that can make mountName nil on login, should resolve itself but make sure we don't crash
+    if mountName == nil then
+        mountName = "None"
+        mountIcon = "Interface\\minimap\\TRACKING\\StableMaster"                                                                                                                   
+    end                                                                                                                                                                            
     if IsOutdoors() == nil then                                                                                                                                                    
         mountColor = MountC5                                                                                                                                                       
     else                                                                                                                                                                           
@@ -308,20 +318,17 @@                                                                                                                                                               
     local name                                                                                                                                                                     
     if IsAltKeyDown() then                                                                                                                                                         
         TitanMountFav1 = i                                                                                                                                                         
-        _, _, TitanMountFavSpell1 = GetCompanionInfo(MountID,i)                                                                                                                    
-        _, name, _, _, _ = GetCompanionInfo(MountID, TitanMountFav1)                                                                                                               
+        _, name, TitanMountFavSpell1 = GetCompanionInfo(MountID,i)                                                                                                                 
         UIErrorsFrame:AddMessage(MountC3.."Favorite #1 set to "..name)                                                                                                             
         TitanUtils_CloseRightClickMenu()                                                                                                                                           
       elseif IsControlKeyDown() then                                                                                                                                               
           TitanMountFav2 = i                                                                                                                                                       
-          _, _, TitanMountFavSpell2 = GetCompanionInfo(MountID,i)                                                                                                                  
-          _, name, _, _, _ = GetCompanionInfo(MountID, TitanMountFav2)                                                                                                             
+          _, name, TitanMountFavSpell2 = GetCompanionInfo(MountID,i)                                                                                                               
           UIErrorsFrame:AddMessage(MountC3.."Favorite #2 set to "..name)
           TitanUtils_CloseRightClickMenu()
         elseif IsShiftKeyDown() then
             TitanMountFav3 = i
-            _, _, TitanMountFavSpell3 = GetCompanionInfo(MountID,i)
-            _, name, _, _, _ = GetCompanionInfo(MountID, TitanMountFav3)
+            _, name, TitanMountFavSpell3 = GetCompanionInfo(MountID,i)
             UIErrorsFrame:AddMessage(MountC3.."Favorite #3 set to "..name)
             TitanUtils_CloseRightClickMenu()
     end

User When Change
Suddendeath2000 Nov 30, 2010 at 22:34 UTC Changed status from New to Verified
CMTitan Jul 12, 2010 at 12:11 UTC Create

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

Facts

Last updated
Nov 30, 2010
Reported
Jul 12, 2010
Status
Verified - QA has verified that the fix has worked.
Type
Patch - Source code patch for review
Priority
Medium - Normal priority.
Votes
0

Reported by

Possible assignees