[Vala] Another interesting List error



Jurg,

    I have another interesting list error for you.   If you use a function to create a list (e.g. a factory method) and return it back, when you access the elements of that list a 14633 Critical error results.  The list is not null, and the elements are not null.  This happens regardless of the way you access the elements, either by looping with foreach or using nth_data.

using GLib;

namespace Error2 {

        public class ListElement {
                private int _someint = 0;
                public int SomeInt {
                        get { return _someint; }
                }

                private string _somestring;
                public string SomeString {
                        get { return _somestring; }
                }

                public void print() {
                        stdout.printf("%d, %s\n",_someint, _somestring);
                }

                public construct (int x, string y) {
                        _someint = x;
                        _somestring = y;
                }
        }


        public class ListConstructor {

                public ref List<ListElement> makeList() {

                        List<ListElement> list;

                        list.append(new ListElement(1,"String 1"));
                        list.append(new ListElement(2,"String 2"));
                        list.append(new ListElement(3,"String 3"));
                        list.append(new ListElement(4,"String 4"));

                        return list;
                }
        }

        static int main(string[] args) {

                ListConstructor lc = new ListConstructor();
                List<ListElement> l = lc.makeList();

                if(l == null) {
                        // Doesn't happen
                        stdout.printf("List is null\n");
                } else {
                        stdout.printf("List is not null\n");
                }

                int x = 0;
                foreach(ListElement le in l) {
                        if(le==null) {
                                // Doesn't happen
                                stdout.printf("Item %d is null\n", x);
                        } else {
                                stdout.printf ("Item %d is not null\n", x);
                        }
                        x++;
                        le.print();
                        // Results in the following error:
                        //      ** (process:14633): CRITICAL **: error2_list_element_print: assertion `ERROR2_IS_LIST_ELEMENT (self)' failed
                }
        }
}

Hope this helps.  Keep up the good work. 

Cayle


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]