Thread Tools Display Modes
12-01-14, 11:06 AM   #1
kawe
A Cyclonian
 
kawe's Avatar
Join Date: Sep 2009
Posts: 40
integer overflow

can anyone explain why this error is occuring when i enter a party or raid grp?

this is the tag;

-----------------------------------------------------------------------------
-- Tags
oUF.Tags.Events['curhp'] = 'UNIT_HEALTH UNIT_MAXHEALTH'
oUF.Tags.Methods['curhp'] = function(unit)
local r,g,b = gradient(UnitHealth(unit)/UnitHealthMax(unit))
return format('|cff%02x%02x%02x %s |cffFFFFFF | |r|cff%02x%02x%02x%d%%|r',
r, g, b, numberize(UnitHealth(unit)),
r, g, b, floor((UnitHealth(unit)/UnitHealthMax(unit))*1000)/10)
end
-----------------------------------------------------------------------------

Message: integer overflow attempting to store -1.#IND
Time: 11/24/14 13:28:19
Count: 46
Stack: [C]: in function `format'
Interface\AddOns\bUI\modules\unitframes.lua:511: in function `?'
Interface\AddOns\bUI\oUF\elements\tags.lua:600: in function `UpdateTag'
Interface\AddOns\bUI\oUF\elements\tags.lua:448: in function <Interface\AddOns\bUI\oUF\elements\tags.lua:444>

Locals: (*temporary) = "|cff%02x%02x%02x %s | |cff%02x%02x%02x%d%%"
(*temporary) = -1.#IND
(*temporary) = 255
(*temporary) = 0
(*temporary) = 0
(*temporary) = -1.#IND
(*temporary) = 255
(*temporary) = 0
(*temporary) = -1.#IND
  Reply With Quote
12-01-14, 12:09 PM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
First of all, let's put that code in a [code] tag so it's nice to read:
Code:
oUF.Tags.Events['curhp'] = 'UNIT_HEALTH UNIT_MAXHEALTH'
oUF.Tags.Methods['curhp'] = function(unit)
   local r,g,b = gradient(UnitHealth(unit)/UnitHealthMax(unit))
   return format('|cff%02x%02x%02x %s |cffFFFFFF | |r|cff%02x%02x%02x%d%%|r', 
      r, g, b, numberize(UnitHealth(unit)), 
      r, g, b, floor((UnitHealth(unit)/UnitHealthMax(unit))*1000)/10)
end
Now, the part I highlighted in orange is what's causing your error. UnitHealthMax can return 0, and we all know dividing by 0 causes black holes.

While you're fixing that, you should also use some variables to avoid having to call UnitHealth and UnitHealthMax multiple times, since function calls are Very Slow:
Code:
oUF.Tags.Events['curhp'] = 'UNIT_HEALTH UNIT_MAXHEALTH'
oUF.Tags.Methods['curhp'] = function(unit)
   local hp, hpMax = UnitHealth(unit), UnitHealthMax(unit)
   if hpMax == 0 then return end
   local hpPercent = hp / hpMax
   local r,g,b = gradient(hpPercent)
   return format('|cff%02x%02x%02x %s |cffFFFFFF | |r|cff%02x%02x%02x%d%%|r', 
      r, g, b, numberize(hp), 
      r, g, b, floor(hpPercent * 1000) / 10
   )
end
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
12-03-14, 08:56 AM   #3
kawe
A Cyclonian
 
kawe's Avatar
Join Date: Sep 2009
Posts: 40
thx

thank you for clarifying
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » integer overflow


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off