Re: emitting the "delete_event" in a "key_press_event" --> crash



Olivier Sessink wrote:

On Wed, 06 Nov 2002 16:15:33 -0500 (EST) "Owen Taylor"
<otaylor redhat com> wrote:

Small test case? Escape is automatically hooked up for GTK+ dialogs and
doesn't usually crash GTK+, so there must be something else going on
here.

(Bug report filed in bugzilla would be appreciated)

I looked more at your source... Sorry its completely broken... "destroy" signal and "destroy_event" are not the same. "destroy" signal (GtkObject) doesnt have a parameters but "destroy_event" (GtkWidget) has. By the way, you are connecting the same function (where
you're doing gfree) to two different signals.


I don't know if the code is valid, so here is my testcase, if the code is
valid please let me know and I'll enter it as a bug.
/*
escape_testcase.c
compile with
gcc escape_testcase.c -o escape_testcase `pkg-config --cflags gtk+-2.0`
`pkg-config --libs gtk+-2.0` */

#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
static void create_testwin();

static gboolean create_window_key_press_event_lcb(GtkWidget
*widget,GdkEventKey *event,GtkWidget *win) {    if (event->keyval ==
GDK_Escape) {           g_signal_emit_by_name(G_OBJECT(win), "delete_event");
/*              gtk_widget_destroy(win);*/
                return TRUE;
        }
        return FALSE;
}

GtkWidget *create_window(GCallback close_func,gpointer close_data) {
        GtkWidget *returnwidget = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        g_signal_connect(G_OBJECT(returnwidget), "delete_event", close_func,
close_data);    g_signal_connect(G_OBJECT(returnwidget), "destroy",

Here's the bug: you connecting to "destroy" and expecting that your handler will get
close_data parameter.


close_func, close_data);        g_signal_connect(G_OBJECT(returnwidget),
"key_press_event", G_CALLBACK(create_window_key_press_event_lcb),
returnwidget);  return returnwidget;
}

typedef struct {
        GtkWidget *win;
        int various_other_data;
} TestWinStruct;

void testwin_destroy_cb(GtkWidget * widget, GdkEvent *event, TestWinStruct *testwin) {
g_signal_handlers_destroy(G_OBJECT(testwin->win));
gtk_widget_destroy(testwin->win);    g_free(testwin);

Here's one more bug - you may call gfree two times.


}

static void testwin_button_clicked_cb(GtkWidget *widget, gpointer data) {
        create_testwin();
}

static void create_testwin() {
        GtkWidget *button;
        TestWinStruct *testwin;
        testwin = g_new(TestWinStruct,1);
        testwin->win = create_window(G_CALLBACK(testwin_destroy_cb), testwin);
        button = gtk_button_new_with_label("create another testwin\n");
        g_signal_connect(G_OBJECT(button), "clicked",
G_CALLBACK(testwin_button_clicked_cb), NULL);
gtk_container_add(GTK_CONTAINER(testwin->win), button);
gtk_widget_show_all(testwin->win);}

int main(int argc, char *argv[]) {

        gtk_init(&argc, &argv);
        create_testwin();
        gtk_main();
}
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Olexiy





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