[gtk-vnc-devel] [PATCH] Gtk-VNC not packed



I don't know if you necessarily want to classify this as a bug, but currently if you create a Gtk-VNC widget but don't pack it, then it will segfault when it tries to draw anything.

Patch to cure the segfault and test program attached.

Rich.

--
Emerging Technologies, Red Hat - http://et.redhat.com/~rjones/
Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod
Street, Windsor, Berkshire, SL4 1TE, United Kingdom.  Registered in
England and Wales under Company Registration No. 03798903
diff -r e8d37fb527c2 src/vncdisplay.c
--- a/src/vncdisplay.c	Tue Jan 15 13:28:03 2008 +0000
+++ b/src/vncdisplay.c	Tue Jan 15 13:59:14 2008 +0000
@@ -536,8 +536,10 @@ static gboolean on_resize(void *opaque, 
 	if (priv->gvnc == NULL || !gvnc_is_initialized(priv->gvnc))
 		return TRUE;
 
-	if (priv->image)
+	if (priv->image) {
 		g_object_unref(priv->image);
+		priv->image = NULL;
+	}
 
 	if (priv->gc == NULL) {
 		priv->null_cursor = create_null_cursor();
@@ -549,20 +551,22 @@ static gboolean on_resize(void *opaque, 
 	}
 
 	visual = gdk_drawable_get_visual(GTK_WIDGET(obj)->window);
-	
-	priv->image = gdk_image_new(GDK_IMAGE_FASTEST, visual, width, height);
-	priv->fb.red_mask = visual->red_mask >> visual->red_shift;
-	priv->fb.green_mask = visual->green_mask >> visual->green_shift;
-	priv->fb.blue_mask = visual->blue_mask >> visual->blue_shift;
-	priv->fb.red_shift = visual->red_shift;
-	priv->fb.green_shift = visual->green_shift;
-	priv->fb.blue_shift = visual->blue_shift;
-	priv->fb.depth = priv->image->depth;
-	priv->fb.bpp = priv->image->bpp;
-	priv->fb.width = priv->image->width;
-	priv->fb.height = priv->image->height;
-	priv->fb.linesize = priv->image->bpl;
-	priv->fb.data = (uint8_t *)priv->image->mem;
+	if (visual) {
+		priv->image =
+			gdk_image_new(GDK_IMAGE_FASTEST, visual, width, height);
+		priv->fb.red_mask = visual->red_mask >> visual->red_shift;
+		priv->fb.green_mask = visual->green_mask >> visual->green_shift;
+		priv->fb.blue_mask = visual->blue_mask >> visual->blue_shift;
+		priv->fb.red_shift = visual->red_shift;
+		priv->fb.green_shift = visual->green_shift;
+		priv->fb.blue_shift = visual->blue_shift;
+		priv->fb.depth = priv->image->depth;
+		priv->fb.bpp = priv->image->bpp;
+		priv->fb.width = priv->image->width;
+		priv->fb.height = priv->image->height;
+		priv->fb.linesize = priv->image->bpl;
+		priv->fb.data = (uint8_t *)priv->image->mem;
+	}
 
 	gtk_widget_set_size_request(GTK_WIDGET(obj), width, height);
 
#include <stdio.h>
#include <gtk/gtk.h>
#include "vncdisplay.h"

#define HOST "192.168.2.129"
#define PORT "5900"
#define USERNAME "" /* Set username and/or password here */
#define PASSWORD ""

static void destroy( GtkWidget *widget,
                     gpointer   data )
{
    gtk_main_quit ();
}

int main( int   argc,
          char *argv[] )
{
    static GtkWidget *window;
    GtkWidget *vnc;
    
    gtk_init (&argc, &argv);
    
    /* Create a new dialog window for the scrolled window to be
     * packed into.  */
    window = gtk_dialog_new ();
    g_signal_connect (G_OBJECT (window), "destroy",
		      G_CALLBACK (destroy), NULL);
    gtk_container_set_border_width (GTK_CONTAINER (window), 0);
    gtk_widget_set_size_request (window, 300, 300);
    
    /* Create a Gtk-VNC widget, but don't pack it. */
    vnc = vnc_display_new ();

    gtk_widget_show (vnc);

    vnc_display_open_host (VNC_DISPLAY (vnc), HOST, PORT);
    vnc_display_set_credential (VNC_DISPLAY (vnc),
				VNC_DISPLAY_CREDENTIAL_USERNAME, USERNAME);
    vnc_display_set_credential (VNC_DISPLAY (vnc),
				VNC_DISPLAY_CREDENTIAL_PASSWORD, PASSWORD);
    
    gtk_widget_show (window);
    
    gtk_main();
    
    return 0;
}

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature



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