lxn / walk

A Windows GUI toolkit for the Go Programming Language
Other
6.78k stars 885 forks source link

TableViewColumn set StyleCell will crash #740

Closed eyotang closed 3 years ago

eyotang commented 3 years ago

The following panic is occurred, while I add StyleCell for TableViewColumn

=====ERROR===== panic: runtime error: index out of range [-1]

goroutine 1 [running, locked to thread]: github.com/lxn/walk/declarative.(tvStyler).StyleCell(0xc0000a56e0, 0xc0004683b8) D:/01.Work/01.code/gocode/pkg/mod/github.com/lxn/walk@v0.0.0-20200924155701-77185e9c4aec/declarative/tableview.go:84 +0x89 github.com/lxn/walk.(TableView).lvWndProc(0xc000468000, 0x7ffffec3ba10, 0x81668, 0xc00000004e, 0x0, 0xe5eca8, 0x0) D:/01.Work/01.code/gocode/pkg/mod/github.com/lxn/walk@v0.0.0-20200924155701-77185e9c4aec/tableview.go:2257 +0x198a github.com/lxn/walk.tableViewNormalLVWndProc(0x81668, 0x4e, 0x0, 0xe5eca8, 0x9cfdc0) D:/01.Work/01.code/gocode/pkg/mod/github.com/lxn/walk@v0.0.0-20200924155701-77185e9c4aec/tableview.go:1934 +0xdf github.com/lxn/walk.(*TableView).WndProc(0xc000468000, 0x4a3e4a, 0x4e, 0x0, 0xe5eca8, 0xc000466390) D:/01.Work/01.code/gocode/pkg/mod/github.com/lxn/walk@v0.0.0-20200924155701-77185e9c4aec/tableview.go:2610 +0x464 github.com/lxn/walk.defaultWndProc(0x4a3e4a, 0x4e, 0x0, 0xe5eca8, 0x0) D:/01.Work/01.code/gocode/pkg/mod/github.com/lxn/walk@v0.0.0-20200924155701-77185e9c4aec/window.go:2159 +0xf0 syscall.Syscall6(0x7ff80e575860, 0x5, 0x7ffffec3ba10, 0x81668, 0xf, 0x0, 0x0, 0x0, 0x0, 0x0, ...) C:/Go/src/runtime/syscall_windows.go:201 +0xfa

====CODE==== Columns: []TableViewColumn{ {Title: "行号", StyleCell: columnStyle, Width: 60}, {Title: "Bar"}, {Title: "Baz", Alignment: AlignFar}, {Title: "Quux", Format: "2006-01-02 15:04:05", Width: 150}, },

====WHAT HAPPENED==== case win.CDDS_ITEMPREPAINT will call tv.styler.StyleCell(&tv.style) as following, but before it col will set to -1: func (tvs tvStyler) StyleCell(style walk.CellStyle) { if tvs.dflt != nil { tvs.dflt.StyleCell(style) }

if styleCell := tvs.colStyleCellFuncs[style.Col()]; styleCell != nil {      << here style.Col() is -1
    styleCell(style)
}

} This will cause crash! Please check style.Col() first.

lxn commented 3 years ago

Thanks for reporting!