Skip to content

widgets.BarChart OOM error #245

Open

Description

If a bar chart's values are all zero, the program tries to allocate all available memory and crashes.

Activity

  1. doatesy commented on Sep 7, 2019

    @doatesy

    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.

  2. doatesy commented on Sep 7, 2019

    @doatesy

    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

  3. barryodev commented on Apr 23, 2021

    @barryodev

    I've come across this same issue, I'm not rendering the barchart data if its all zeros but the bug still exists

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ 换网址