[Gtk-sharp-list] displaying window problem

Bjoern Schiessle bes@schiessle.org
Tue, 21 Dec 2004 15:35:09 +0100


Hello!
I want to open a new window from my program to display some html content.
Therefor i have wrote this class:

using System;
using Gtk;
using Gecko;

class HTMLView
{   
    Window HTMLWindow;
    
    public HTMLView(string title, string text)
        {
            string page = "<html><head><title>" + title + "</title></head>" +
                "<body><h1>" + title + "</h1><p>" + text + "<p></body></html>";
            HTMLWindow = new Window (title);
            Gecko.WebControl webctrl = new WebControl();
            webctrl.SetSizeRequest(450, 350);
            HTMLWindow.Add(webctrl);
            HTMLWindow.ShowAll();
            HTMLWindow.DeleteEvent += new DeleteEventHandler(HTMLView_Delete);
            webctrl.RenderData(page, "file:///tmp", "text/html");            
        }
    
    void HTMLView_Delete (System.Object o, DeleteEventArgs args)
        {
            HTMLWindow.Destroy();
        }
}


In the main window i have a simple function to load the HTMLView if i
click a special button:

void HTMLButton_clicked (System.Object o, EventArgs args)
    {
        new HTMLView("foo", "bar");
    }

Now i can start one or more HTMLView windows and also close some of them.
But if i have closed the HTMLView window which were started in the first
place and than try to start again a HTMLView the whole program crashes
with this error message:

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object
in (unmanaged) (wrapper managed-to-native) Gtk.Widget:gtk_widget_show_all (intptr)
in <0x00004> (wrapper managed-to-native) Gtk.Widget:gtk_widget_show_all (intptr)
in <0x0001f> Gtk.Widget:ShowAll ()
in <0x00153> HTMLView:.ctor (string,string)
in <0x0005a> gcard:on_HTMLButton_clicked (object,System.EventArgs)
in <0x00069> (wrapper delegate-invoke) System.MulticastDelegate:invoke_void_object_EventArgs (object,System.EventArgs)
in <0x0012d> GtkSharp.voidObjectSignal:voidObjectCallback (intptr,int)
in <0x0005a> (wrapper native-to-managed) GtkSharp.voidObjectSignal:voidObjectCallback (intptr,int)
in (unmanaged) (wrapper managed-to-native) Gtk.Application:gtk_main ()
in <0x00004> (wrapper managed-to-native) Gtk.Application:gtk_main ()
in <0x00007> Gtk.Application:Run ()
in <0x0002a> gcard:Main (string[])

As far as i can see, the problem appear if HTMLWindow.ShowAll(); were
called.

Can someone help me?

Cheers,
Bjoern