Open ghost opened 5 years ago
I can confirm I am having the same issue. I am using bar charts to display switch positions (1 = on, 0 being off), and 5 switches in a bar chart. If all are 0, the whole ui crashes, my CPU usage goes through the roof, and its all rather unpleasant.
I just found the issue, and I've put in a pretty dodgy fix on my bar chart val
I added the following on line 48 of termui/v3/widgets/barchart.go
if maxVal == 0 {
maxVal = 1
}
So that section now looks like this
maxVal := self.MaxVal
if maxVal == 0 {
maxVal, _ = GetMaxFloat64FromSlice(self.Data)
}
if maxVal == 0 {
maxVal = 1
}
barXCoordinate := self.Inner.Min.X
for i, data := range self.Data {
Basically, if the maxVal
is still 0 after the last check, then set it to 1 (because 0 / 0 did not go down so well on line 53)
I would submit this, but Git and Me just dont understand each other, and someone probably can come up with a more elegant solution. This is a bit of a hack to get it working, but it did the job for me.
Cheers
I've come across this same issue, I'm not rendering the barchart data if its all zeros but the bug still exists
If a bar chart's values are all zero, the program tries to allocate all available memory and crashes.