Reputation: 79
I have a packet forwarding application that is mostly working quite well. There is a gtk3 foreach loop that runs every 2 seconds to update channel forwarding statistics in the treeview. To save resources this only runs when the treeview window has the focus.
MainListStore.ForEach(func(tmodel *gtk.TreeModel, path *gtk.TreePath, iterfe *gtk.TreeIter) bool { // get the channel no value, _ := tmodel.GetValue(iterfe, MCOL_INPORT) goValue, _ := value.GoValue() key := goValue.(int) // copy stats to liststore Mutex.Lock() err := MainListStore.Set(iterfe, []int{MCOL_STATPIX, MCOL_STATINT, MCOL_SPDIN, MCOL_SPDOUT}, []interface{}{Pixes[Statmap[key][0]], Statmap[key][0], Statmap[key][1], Statmap[key][2]}) Mutex.Unlock() if err != nil { Logit.Printf("Error: error updating stats chan %s, %v", key, err) } return false // keep iterating })
1: bad pointer crash. I kept this process running for some time and eventually got a crash:
runtime: bad pointer in frame github.com/gotk3/gotk3/gtk.(*TreeModel).ForEach.func1 at 0xc0007df378: 0x2
fatal error: invalid pointer found on stack
My best guess is that between starting the loop and setting values in the liststore, the Treeiter became invalid.
Any suggestions as to what went wrong and how to avoid it would be appreciated.
Is there a way to streamline getting the int key from treemodel? Rather than declaring a *gtk.value, then a govalue interface then the int? Most of which presumably end up on the heap, which brings me to:
Thanks for any expert advice!
Upvotes: 0
Views: 49