emer / etable

Data table structure in Go, now developed at https://github.com/cogentcore/core/tree/main/tensor
BSD 3-Clause "New" or "Revised" License
115 stars 7 forks source link

plot may run off end of data #31

Open rgobbel opened 3 years ago

rgobbel commented 3 years ago

If the table driving a plot shrinks, Plot2D.GenPlotXY can run off the end of the data, causing a segfault. The problematic code (that I know of) is at line 205 of xyplot.go:

199 // Use string labels for X axis if X is a string
200 xc := pl.Table.Table.Cols[xi]
201 if xc.DataType() == etensor.STRING {
202     xcs := xc.(*etensor.String)
203     vals := make([]string, pl.Table.Len())
204     for i, dx := range pl.Table.Idxs {
205         vals[i] = xcs.Values[dx]
206     }
207     plt.NominalX(vals...)
208 }

In the case that I've seen, the table had 15 entries for the first phase of a run, and was then resized to only 10 rows for the second phase. I've worked around the issue in the calling code by calling IdxView.DeleteInvalid after shrinking the data source table, but I really think there should be a check somewhere in etable itself.