[Gtk-sharp-list] Maybe a bug in ListStore under Windows

Michele Beltrame admin at talkblade.info
Sun Jul 3 07:52:40 EDT 2005


Hi!

I'm trying to iterate trhough a ListStore: under Linux with mono 1.1.8
it works, but on Windows XP with mono 1.1.8 it throws a
NullReferenceException.

I created a test code, here it goes:

---Code BEGIN---
using System;
using Gtk;

public class XNWindow : Gtk.Window {
	private TreeView tv;
	private ListStore ls;

	public XNWindow(string wname): base(wname)
	{
		// Create TreeView
		tv = new TreeView();
		tv.HeadersVisible = true;

		// Define a column
		TreeViewColumn col = new TreeViewColumn();
		CellRenderer colr = new CellRendererText();
		col.Title = "Azienda";
		col.PackStart(colr, true);
		col.AddAttribute(colr, "text", 0);
		tv.AppendColumn(col);

		// Create and fill the ListStore for the TreeView
		ls = new ListStore(typeof(string));
		tv.Model = ls;
		for (int i = 0; i <= 10; i++) {
			ls.AppendValues(Convert.ToString(i));
		}

		Button b = new Button("Foreach");
		b.Clicked += Foreach_clicked;
		
		VBox v = new VBox();
		v.Add(tv);
		v.Add(b);
		Add(v);
	}

	private void Foreach_clicked(object o, EventArgs a)
	{
		ls.Foreach(new TreeModelForeachFunc(MyPrintForeach));
	}

	private bool MyPrintForeach(TreeModel model, TreePath path, TreeIter iter)
	{
		Console.WriteLine ((string)ls.GetValue(iter, 0));

		// We return false so the loop will keep on going
		return false;
	}

}

class XNMain
{
	public static void Main (string[] args)
	{
		Application.Init();
		XNWindow mainw = new XNWindow("ListStore possible bug");
		mainw.ShowAll();
		Application.Run();
	}
}
---Code END---

It first fills a ListStore and then tries to print out its elements when
the Foreach button is pressed. This is what I get under Windows:

---Output BEGIN---
0
1

Unhandled Exception: System.NullReferenceException: Object reference not
set to an instance of an object
in <0x00000> <unknown method>
in (wrapper managed-to-native) Gtk.ListStore:gtk_tree_model_foreach
(intptr,GtkSharp.TreeModelForeachFuncNative,intptr)
in <0x00046> Gtk.ListStore:Foreach (Gtk.TreeModelForeachFunc func)
in <0x00044> XNWindow:Foreach_clicked (System.Object o, System.EventArgs a)
in (wrapper delegate-invoke)
System.MulticastDelegate:invoke_void_object_EventAr
gs (object,System.EventArgs)
in <0x000bb> GtkSharp.voidObjectSignal:voidObjectCallback (IntPtr arg0,
Int32 key)
in (wrapper native-to-managed)
GtkSharp.voidObjectSignal:voidObjectCallback (int
ptr,int)
in <0x00000> <unknown method>
in (wrapper managed-to-native) Gtk.Application:gtk_main ()
in <0x00007> Gtk.Application:Run ()
in <0x00038> XNMain:Main (System.String[] args)
---Output END---

It seems to print the first two entires correctly, but then it throws
the exeption. I tried with other ListStore objects with different and
more complex content and I always get this exception when trying to
"Foreach" on them. However, this happens only on Windows.

	Thanks, Michele.

-- 
Michele Beltrame
http://www.massainforme.it/mb/
ICQ# 76660101


More information about the Gtk-sharp-list mailing list