Lua Error upon world spawn
patrickdoane opened this issue ยท 2 comments
Error Count will continue to rise until the disable addons dialog is displayed. A workaround (without digging too deep into the lua myself) is to simply select any target upon spawn and close the Lua error dialog.
I suspect that in LHGWSTMain.UpdateSwingFrames, target_percent is never initialized on load since the player has no target, causing the division by zero.
Stack trace:
Message: ...dOns\WeaponSwingTimer\WeaponSwingTimer_MainFrame.lua:32: Division by zero
Time: Sat May 18 13:39:08 2019
Count: 1
Stack: ...dOns\WeaponSwingTimer\WeaponSwingTimer_MainFrame.lua:32: Division by zero
...dOns\WeaponSwingTimer\WeaponSwingTimer_MainFrame.lua:32: in function `UpdateSwingFrames'
...ce\AddOns\WeaponSwingTimer\WeaponSwingTimer_Core.lua:117: in function <...ce\AddOns\WeaponSwingTimer\WeaponSwingTimer_Core.lua:116>
...ce\AddOns\WeaponSwingTimer\WeaponSwingTimer_Core.lua:124: in function <...ce\AddOns\WeaponSwingTimer\WeaponSwingTimer_Core.lua:122>
Locals: play_weap_speed = 2.900000
play_swing_time = 0
tar_weap_speed = 0
tar_swing_time = 0
main_frame = WSTMainFrame {
0 = <userdata>
player_swing_frame = WSTPlayerSwingFrame {
}
target_swing_frame = WSTTargetSwingFrame {
}
main_texture = <unnamed> {
}
texture = <unnamed> {
}
}
player_swing_frame = WSTPlayerSwingFrame {
0 = <userdata>
texture = <unnamed> {
}
}
target_swing_frame = WSTTargetSwingFrame {
0 = <userdata>
texture = <unnamed> {
}
}
(*temporary) = WSTPlayerSwingFrame {
0 = <userdata>
texture = <unnamed> {
}
}
(*temporary) = 298
(*temporary) = <userdata>
(*temporary) = 300
(*temporary) = "Division by zero"
And my AddOns folder is:
Adding a simple if/then statement seemed to help the issue for me (if anyone else is looking at this issue and wondering what to do).
In Interface/Addons/WeaponSwingTimer/WeaponSwingTimer_MainFrame.lua, update function declaration LHGWSTMain.UpdateSwingFrames to the following:
LHGWSTMain.UpdateSwingFrames = function(play_weap_speed, play_swing_time, tar_weap_speed, tar_swing_time)
-- Update the alpha
local main_frame = LHGWSTMain.main_frame
if LHG_WeapSwingTimer_Settings.in_combat then
main_frame:SetAlpha(LHG_WeapSwingTimer_Settings.in_combat_alpha)
else
main_frame:SetAlpha(LHG_WeapSwingTimer_Settings.ooc_alpha)
end
-- Update the player swing frame
local player_swing_frame = LHGWSTMain.main_frame.player_swing_frame
player_percent = 1 - (play_swing_time / play_weap_speed)
player_swing_frame:SetWidth((main_frame:GetWidth() - 2) * player_percent)
-- Update the target swing frame
local target_swing_frame = LHGWSTMain.main_frame.target_swing_frame
if (tar_weap_speed > 1) then
target_percent = 1 - (tar_swing_time / tar_weap_speed)
target_swing_frame:SetWidth((main_frame:GetWidth() - 2) * target_percent)
end
end
This simply adds a conditional to check for tar_weap_speed > 0
before setting the width of the frame.