Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

GetIter() is broken #65

ndrchvzz opened this Issue Jul 17, 2011 · 4 comments


None yet
2 participants

Regarding this func in gtk.go:
func (v *GtkTreeModel) GetIter(iter *GtkTreeIter, path *GtkTreePath) bool

There is something wrong with it, as the path parameter is not passed to C._gtk_tree_model_get_iter(), the newly created path_ is passed instead, and this error is generated:
Gtk-CRITICAL **: IA__gtk_tree_model_get_iter: assertionpath->depth > 0' failed`

This fixes the error:

func (v *GtkTreeModel) GetIter(iter *GtkTreeIter, path *GtkTreePath) bool {
    ret := gboolean2bool(C._gtk_tree_model_get_iter(v.TreeModel, &iter.TreeIter, unsafe.Pointer(path)))
    return ret

However, when using GetValue() with the resulting iter like that:
treeModel.GetValue(&iter, 1, &value)
I get this:
Gtk-CRITICAL **: gtk_tree_store_get_value: assertionVALID_ITER (iter, tree_store)' failed`


mattn commented Oct 12, 2011

Would you give me a example code to reproduce it?

I haven't been working at this code for a while, here it is anyway, I hope it helps:

package packages

import (

type Viewer struct {
    treeStore *gtk.GtkTreeStore
    treeView *gtk.GtkTreeView
    swin *gtk.GtkScrolledWindow

func NewViewer() (*Viewer) {
    treeStore := gtk.TreeStore(gdkpixbuf.GetGdkPixbufType(), glib.G_TYPE_STRING)
    treeView := gtk.TreeView()

    treeView.AppendColumn(gtk.TreeViewColumnWithAttributes("pixbuf", gtk.CellRendererPixbuf(), "pixbuf", 0))
    treeView.AppendColumn(gtk.TreeViewColumnWithAttributes("text", gtk.CellRendererText(), "text", 1))

    swin := gtk.ScrolledWindow(nil, nil)

    treeView.Connect("row_activated", func() {
        var path *gtk.GtkTreePath
        var column *gtk.GtkTreeViewColumn
        treeView.GetCursor(&path, &column)
        fmt.Println(path.String(), path.GetDepth())

        treeModel := treeStore.ToTreeModel()
        var iter gtk.GtkTreeIter
        treeModel.GetIter(&iter, path)

        var value glib.GValue
        treeModel.GetValue(&iter, 1, &value)

//      fmt.Println(pathToFile(path.String()))

    return &Viewer{treeStore, treeView, swin}

func (viewer *Viewer) Update(projectName string, pkgs *vector.Vector) {
    for _, p := range *pkgs {
        var cp *pkg = p.(*pkg)
        viewer.addPackage(cp, nil)

func (viewer *Viewer) Widget() gtk.WidgetLike {
    return viewer.swin  

func (viewer *Viewer) addPackage(p *pkg, parent *gtk.GtkTreeIter) {
    // adds package icon to parent
    var piter gtk.GtkTreeIter
    viewer.treeStore.Append(&piter, parent)
    viewer.treeStore.Set(&piter, gtk.Image().RenderIcon(

    // adds files
    for _, obj := range *p.Files() {
        var f *os.File = obj.(*os.File)

        var fiter gtk.GtkTreeIter
        viewer.treeStore.Append(&fiter, &piter)
        viewer.treeStore.Set(&fiter, gtk.Image().RenderIcon(
            gtk.GTK_STOCK_FILE, gtk.GTK_ICON_SIZE_SMALL_TOOLBAR, "").Pixbuf,

    // adds sub-packages
    for _, obj := range *p.Packages() {
        var p *pkg = obj.(*pkg)
        viewer.addPackage(p, &piter)

func fileName(name string) string {
    return name[strings.LastIndex(name, "/") + 1 : len(name) - 3]

func pathToFile(path string) *os.File {
    return nil

mattn commented Oct 15, 2011

Ah, ok.
Please check latest.


mattn commented Dec 25, 2014

Already fixed.

@mattn mattn closed this Dec 25, 2014

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