Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom TreeModel implementations (that are Trees) broken #130

Closed
mlizard32 opened this issue Oct 28, 2015 · 3 comments
Closed

Custom TreeModel implementations (that are Trees) broken #130

mlizard32 opened this issue Oct 28, 2015 · 3 comments

Comments

@mlizard32
Copy link

When creating a custom tree model that is a Tree(not a simple list) like in Demos\gtkD\DemoCustomList, the model will crash when trying to expand child nodes.

in TreeModelIF.d "iterChildren" "iterHasChild" etc changed from
public bool iterChildren(TreeIter iter, TreeIter parent);
to
public bool iterChildren(out TreeIter iter, TreeIter parent);

when I revert related changes my custom TreeModel works fine with children.

gtk 3.18, windows

@MikeWey
Copy link
Member

MikeWey commented Oct 29, 2015

This change happened in the 3.0 release.

Initializing the iter in your implementation of iterChildren should fix the problem.

@mlizard32
Copy link
Author

I see in the gtk docs that iter_children has "iter" marked as "out", but I'm not seeing that behavior in the gtk3
the following is currently working for me.

override bool iterChildren(TreeIter iter, TreeIter parent)
    {
        RMObject rmObj;
        RMObject parentObj;

assert(iter !is null) //iter passed in is not uninitialized like expected
        if ( parent is null )
        {
            rmObj = cast(RMObject)root.getChildren[0];
        }
        else
        {
            parentObj = cast(RMObject)parent.userData;

            auto children = parentObj.getChildren;

            if(children.length == 0)
                return false;

            rmObj = cast(RMObject) children[0];
        }
        /* Set iter to first item in list */
        iter.stamp     = stamp;
        iter.userData  = cast(void*)rmObj;

        return true;
    }

when doing it this way

override bool iterChildren(out TreeIter iter, TreeIter parent)
    {
        RMObject rmObj;
        RMObject parentObj;
assert(iter !is null) //iter passed in is not uninitialized like expected
        if ( parent is null )
        {
            rmObj = cast(RMObject)root.getChildren[0];
        }
        else
        {
            parentObj = cast(RMObject)parent.userData;

            auto children = parentObj.getChildren;

            if(children.length == 0)
                return false;

            rmObj = cast(RMObject) children[0];
        }

        iter = new TreeIter(); //initializing new Iter
        iter.stamp     = stamp;
        iter.userData  = cast(void*)rmObj;

        return true;
    }

it breaks later in iterParent because the child passed into iterParent is invalid

When initializing the Tree Model, I initialize TreeIter for every node in my tree including children
like this

void appendObj(RMObject obj)
    {
        TreeIter iter;
        TreePath path;

//this can be a path with depth(ie child)
        path = getPathFromObject(obj);
        assert(path !is null);
        iter = new TreeIter();
        getIter(iter, path);

        rowInserted(path, iter);
    }

maybe that is where i'm going wrong, but it doesn't make sense to me to allocate a new iterator everytime you iterate through children.

@MikeWey
Copy link
Member

MikeWey commented Nov 1, 2015

Does commit 8ce74d8 make any difference with this issue?

@MikeWey MikeWey closed this as completed May 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants