Attr in wxPython= wx.grid.GridCellAttr() error reporting

Question:

wx._ core.wxAssertionError : C++ assertion “m_ count > 0” failed at … \src\common\ object.cpp (352) in wxRefCounter::DecRef(): invalid ref data count

Causes of the problem:

        attr = wx.grid.GridCellAttr()  
        for i in range(len(lis)):
            editor = wx.grid.GridCellBoolEditor()
            self.SetCellEditor(i + 1, 0, editor)
            self.SetCellRenderer(i + 1, 0, wx.grid.GridCellBoolRenderer())
            for j in range(len(lis[i])):
                self.SetCellValue(i + 1, j + 1, lis[i][j])
                attr.SetReadOnly()
                self.SetAttr(i + 1, j + 1, attr)

Solution 1:

        #attr = wx.grid.GridCellAttr() #Modify the part
        for i in range(len(list1)):
          attr = wx.grid.GridCellAttr()#Modify the part
          self.SetCellValue(i + 1, j + 1, list1[i][j])
          attr.SetReadOnly()
          self.SetAttr(i + 1, j + 1, attr)
         
            	

Solution 2:

        attr = wx.grid.GridCellAttr()
        for j in range(len(list1[i])):
              self.SetCellValue(i + 1, j + 1, list1[i][j])
              attr.SetReadOnly()
              atttr.IncRef()#Modify the part;this will leak the GridCellAttr, because the destructor is not called
              self.SetAttr(i + 1, j + 1, attr)

Read More: