classpower: BugSack error when max power changes
chiel opened this issue ยท 14 comments
Hello, I think I have found an issue with the classpower
element. When the max
amount of charges switches for a monk's chi (done through the level 45 "Ascension" talent), the error below gets thrown.
It looks like there may be an issue with the element.__max
somehow not getting set. Can someone confirm if this is working or if I am just messing stuff up?
I'm creating the element like this:
local classPowerFrame = CreateFrame('Frame', nil, UIParent)
local ClassPower = {}
for i = 1, 10 do
local Bar = CreateFrame('StatusBar', nil, self)
Bar:SetStatusBarTexture(addon.media.texture)
Bar:SetParent(classPowerFrame)
Bar:SetSize(16, 6)
Bar:SetPoint('TOPLEFT', classPowerFrame, 'TOPLEFT', (i - 1) * 17, 0)
ClassPower[i] = Bar
end
self.ClassPower = ClassPower
and the error:
133x oUF\elements\classpower.lua:129: attempt to compare number with nil
[string "@oUF\elements\classpower.lua"]:129: in function <oUF\elements\classpower.lua:84>
[string "=(tail call)"]: ?
[string "@oUF\events.lua"]:81: in function <oUF\events.lua:79>
[string "=(tail call)"]: ?
Locals:
self = oUF_AelUIplayerPlayer {
0 = <userdata>
__tags = <table> {
}
UNIT_ENTERED_VEHICLE = <function> defined @oUF\ouf.lua:46
UNIT_SPELLCAST_CHANNEL_START = <function> defined @oUF\elements\castbar.lua:314
unitEvents = <table> {
}
UNIT_HEALTH_FREQUENT = <function> defined @oUF\elements\health.lua:177
UNIT_MAXHEALTH = <function> defined @oUF\elements\health.lua:177
__elements = <table> {
}
UNIT_POWER_FREQUENT = <table> {
}
Power = <unnamed> {
}
UNIT_DISPLAYPOWER = <function> defined @oUF\elements\power.lua:247
UNIT_SPELLCAST_NOT_INTERRUPTIBLE = <function> defined @oUF\elements\castbar.lua:243
style = "AelUI:player"
UNIT_EXITED_VEHICLE = <function> defined @oUF\ouf.lua:46
UNIT_CONNECTION = <table> {
}
UNIT_SPELLCAST_START = <function> defined @oUF\elements\castbar.lua:107
unit = "player"
UNIT_SPELLCAST_DELAYED = <function> defined @oUF\elements\castbar.lua:265
UNIT_SPELLCAST_STOP = <function> defined @oUF\elements\castbar.lua:292
UNIT_SPELLCAST_INTERRUPTED = <function> defined @oUF\elements\castbar.lua:193
UNIT_SPELLCAST_CHANNEL_STOP = <function> defined @oUF\elements\castbar.lua:408
UNIT_SPELLCAST_CHANNEL_UPDATE = <function> defined @oUF\elements\castbar.lua:378
UNIT_SPELLCAST_INTERRUPTIBLE = <function> defined @oUF\elements\castbar.lua:221
UNIT_MAXPOWER = <table> {
}
PLAYER_ENTERING_WORLD = <function> defined @oUF\ouf.lua:194
UNIT_FACTION = <table> {
}
PLAYER_TALENT_UPDATE = <function> defined @oUF\elements\classpower.lua:209
Health = <unnamed> {
}
UNIT_FLAGS = <table> {
}
colors = <table> {
}
Castbar = <unnamed> {
}
UNIT_POWER_BAR_SHOW = <function> defined @oUF\elements\power.lua:247
ClassPower = <table> {
}
UNIT_POWER_BAR_HIDE = <function> defined @oUF\elements\power.lua:247
UNIT_SPELLCAST_FAILED = <function> defined @oUF\elements\castbar.lua:165
}
event = "UNIT_POWER_FREQUENT"
unit = "player"
powerType = "CHI"
element = <table> {
1 = <unnamed> {
}
2 = <unnamed> {
}
3 = <unnamed> {
}
4 = <unnamed> {
}
5 = <unnamed> {
}
6 = <unnamed> {
}
7 = <unnamed> {
}
8 = <unnamed> {
}
9 = <unnamed> {
}
10 = <unnamed> {
}
}
cur = 1
max = 5
mod = 1
oldMax = nil
powerID = 12
numActive = 1.900000
(*temporary) = 5
(*temporary) = 5
(*temporary) = 1
(*temporary) = 5
(*temporary) = <function> defined =[C]:-1
(*temporary) = <unnamed> {
0 = <userdata>
background = <unnamed> {
}
}
(*temporary) = 0
(*temporary) = "attempt to compare number with nil"
ClassPowerType = "CHI"
SPELL_POWER_COMBO_POINTS = 4
ClassPowerID = 12
SPEC_WARLOCK_DESTRUCTION = 3
Please let me know if I can help in debugging anything. :)
This may happen if UnitPowerMax
returned nil for whatever reason. Could you test with the fix-classpower-533
branch and tell us if it fixes the issue or if it creates some undesired side-effects?
Just tried it out, but unfortunately the issue persists. I've tried doing a little bit more debugging by adding some debugging print
statements around the problem code, as such:
oldMax = element.__max
+ print('MAX', max)
+ print('OLD MAX', oldMax)
if(max ~= oldMax) then
if(max < oldMax) then
for i = max + 1, oldMax do
element[i]:Hide()
element[i]:SetValue(0)
end
end
+ print('SET __MAX', max)
element.__max = max
end
With the "Ascension" talent selected and doing a /reload
, I see the following output:
MAX 6
OLD MAX 10
SET __MAX 6
All fine, it sets the new element.__max
as expected upon initialising the element.
then, switching to "Fist of the White Tiger", the following logs happen:
MAX 6
OLD MAX 6
MAX 5
OLD MAX 6
SET __MAX 5
Looks great! However, then when switching back to "Ascension":
MAX 6
OLD MAX nil
MAX 6
OLD MAX nil
MAX 6
OLD MAX nil
MAX 6
OLD MAX nil
MAX 6
OLD MAX nil
Not sure why it says this 5 times. It feels like perhaps there are multiple event handlers being attached or so? Below a screenshot of the above, with more of the output out of the chat frame, but you get the idea.
Please let me know if there's any additional debugging you'd like me to do. :)
It's my own layout I'm working on, I don't think I'm doing anything weird, but I can try to reproduce with a clean layout - maybe I'm doing something weird. I'll get back to you :)
Okay, I can't seem to reproduce this either with a new layout spawning just a player frame, so I must be messing something up in my layout... weird. I am changing parents on some of the elements though, could that be the problem?
Sorry for wasting your time!
So the issue seems to be that I'm creating some custom backgrounds for each of the power cells, and showing/hiding those myself since if I add .bg
widget on each chi bar, it gets hidden. I want it to always be visible and only fill/empty based on whether that amount of chi is reached.
Is there some sane way of doing this without making a custom bg thing?
I cannot reproduce this with my layout. Can you provide a link to the layout you are using?
Use the element's PostUpdate, check if max
has changed (3rd argument, see documentation in elements/classpower.lua
) and re-size and re-position your background art accordingly. Parent/attach the background art to your container frame (classPowerFrame in your example code above) not to the individual bars. You can use the .isEnabled
attribute on classpower element to show/hide your background art/container frame.
Okay, that sounds a lot cleaner than what I am done now, cause I just made a frame and manually attached a UNIT_MAXPOWER
event and then did stuff based on that. Thanks for the insight!
@Rainrider aye I just saw that while looking for answers to another issue I'm having, should be a very small change on my end - thanks for the heads-up!
@Rainrider thanks for pinging me, I was just debugging why my classpower bars had disappeared haha. I've opted to use __isEnabled
for the time being to avoid having to hook up everything else, but I'll get around that in the future.