Re: GtkItemFactory stuff troubles



I've got this from valgrind (debugging the full app, but I got similar things debugging the one listed below)
so I think somewhere I've messed up gdk events and callbacks stuff. But so far, I'm still stuck... :(


(ending of valgrind.log:)
==4713== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 148 from 13)
==4713== ==4713== 1 errors in context 1 of 1:
==4713== Jump to the invalid address stated on the next line
==4713==    at 0x5E5D3E0: ???
==4713==    by 0x445A659: gdk_event_dispatch (gdkevents-x11.c:2369)
==4713==    by 0x47AFE87: g_main_context_dispatch (gmain.c:1960)
==4713==    by 0x47B372F: g_main_context_iterate (gmain.c:2591)
==4713==    by 0x47B3B9E: g_main_loop_run (gmain.c:2799)
==4713==    by 0x417B418: gtk_main (gtkmain.c:1218)
==4713==    by 0x804CE22: main (news_main.c:718)
==4713==  Address 0x5e5d3e0 is not stack'd, malloc'd or (recently) free'd
==4713== --4713-- --4713-- used_suppression: 240 glib type registry
--4713-- used_suppression:    148 dl-hack3-cond-1
==4713== ==4713== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 148 from 13)


Emmanuel Thomas-Maurin


Ardhan Madras wrote:
Hi,

At first as a standard procedure of course ;p, you may want to try to debug it, just enable debugging information when 
compiling, sometime with "nicely" gdb tell you which part making that mess.

                - Ardhan


--- manutm007 gmail com wrote:

From: Manu TM <manutm007 gmail com>
To: GTK mailing list <gtk-app-devel-list gnome org>
Subject: GtkItemFactory stuff troubles
Date: Sun, 24 Jan 2010 14:05:48 +0100

Hi,

I'm having troubles with GTkItemFactory stuff. So I've trimmed the buggy part of my app (about
5000 lines long) to something small. The problem is I get a segfault whenever I press <ctrl><R>
to open the RSS Feed window immediately followed by <esc> to close the window so I think there is
something wrong with the menu bar and accelerators but can't find out what.

Thanks in advance for any hints. Here is the code:


#define _GNU_SOURCE
#define _ISOC99_SOURCE
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
static GtkWidget *win;
static GtkWidget *menu_bar;

static gint esc_key_pressed(GtkWidget *dialog, GdkEventKey *event, gpointer data)
{
        if (event->keyval == GDK_Escape) {
                gtk_dialog_response(GTK_DIALOG(dialog), GTK_RESPONSE_CANCEL);
                return TRUE;
        }
        else
                return FALSE;
}

static void get_new_url()
{
        GtkWidget       *dialog;
        GtkWidget       *vbox, *hbox, *label;
        GtkWidget       *entry;
        gint            response;

        dialog = gtk_dialog_new_with_buttons("RSS Feed", GTK_WINDOW(win),
                                GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
                                GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                                GTK_STOCK_REMOVE, GTK_RESPONSE_NO,
                                GTK_STOCK_HOME, GTK_RESPONSE_YES,
                                GTK_STOCK_OK, GTK_RESPONSE_OK, NULL);
        gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER);

        g_signal_connect(G_OBJECT(dialog), "key-press-event",
                G_CALLBACK(esc_key_pressed), NULL);

        vbox = gtk_vbox_new(FALSE, 0);
        gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), vbox, FALSE, TRUE, 0);
        gtk_container_set_border_width(GTK_CONTAINER(GTK_BOX(vbox)), 15);
        hbox = gtk_hbox_new(FALSE, 0);
        label = gtk_label_new("Enter new URL: ");
        gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, TRUE, 0);
        entry = gtk_entry_new();
        gtk_entry_set_max_length(GTK_ENTRY(entry), 255);
        gtk_entry_set_width_chars(GTK_ENTRY(entry), 80);
        gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, TRUE, 0);
        gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);

        gtk_widget_show_all(dialog);

        while ((response = gtk_dialog_run(GTK_DIALOG(dialog))) != GTK_RESPONSE_CANCEL) {
        }
        gtk_widget_destroy(dialog);
        return;
}

static void quit()
{
        gtk_main_quit();
        return;
}

static GtkItemFactoryEntry menu_item[] = {
        {"/File",                     NULL, NULL, 0, "<Branch>", NULL},

        {"/File/_Open",                       "<control>O", NULL, 0, "<StockItem>",
                                        (gconstpointer)GTK_STOCK_OPEN},

        {"/File/_RSS Feed",           "<control>R", get_new_url, 0, "<StockItem>",
                                        (gconstpointer)"news_rss_icon"},

        {"/File/sep",                 NULL, NULL, 0, "<Separator>", NULL},

        {"/File/_Quit",                       "<control>Q", quit, 0, "<StockItem>",
                                        (gconstpointer)GTK_STOCK_QUIT},

        {"/Edit",                     NULL, NULL, 0, "<Branch>", NULL},

        {"/Edit/_Preferences",                "<control>P", NULL, 0, "<StockItem>",
                                        (gconstpointer)GTK_STOCK_PREFERENCES},

        {"/Control",                  NULL, NULL, 0, "<Branch>", NULL},

        {"/Control/Play",             "<control>J", NULL, 0, "<StockItem>",
                                        (gconstpointer)GTK_STOCK_MEDIA_PLAY},

        {"/Control/Pause",            "<control>K", NULL, 0, "<StockItem>",
                                        (gconstpointer)GTK_STOCK_MEDIA_PAUSE},

        {"/Control/Reload",           "<control>L", NULL, 0, "<StockItem>",
                                        (gconstpointer)GTK_STOCK_MEDIA_REWIND},

        {"/Help",                     NULL, NULL, 0, "<Branch>", NULL},

        {"/Help/Quick Help",          "F1", NULL, 0, "<StockItem>",
                                        (gconstpointer) GTK_STOCK_HELP},

        {"/Help/_About",              "<control>A", NULL, 0, "<StockItem>",
                                        (gconstpointer)GTK_STOCK_ABOUT}
};

static gint n_menu_items = sizeof(menu_item) / sizeof(menu_item[0]);

GtkWidget *get_menubar()
{
        GtkItemFactory  *item_factory;
        GtkAccelGroup   *accel_group;

        accel_group = gtk_accel_group_new();
        item_factory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<main>", accel_group);
        gtk_item_factory_create_items(item_factory, n_menu_items, menu_item, NULL);
        gtk_window_add_accel_group(GTK_WINDOW(win), accel_group);
        return gtk_item_factory_get_widget(item_factory, "<main>");
}

int main(int argc, char *argv[])
{
        GtkWidget       *hbox1, *hbox2;

        gtk_init(&argc, &argv);
        
        win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        gtk_window_set_title(GTK_WINDOW(win), "Feed Reader");
        gtk_container_set_border_width(GTK_CONTAINER(win), 0);
        g_signal_connect(G_OBJECT(win), "delete_event", G_CALLBACK(gtk_main_quit), NULL);

        hbox1 = gtk_hbox_new(FALSE, 0);
        gtk_container_add(GTK_CONTAINER(win), hbox1);
        menu_bar = get_menubar(win);
        gtk_box_pack_start(GTK_BOX(hbox1), menu_bar, FALSE, FALSE, 0);
        hbox2 = gtk_hbox_new(FALSE, 0);
        gtk_box_pack_start(GTK_BOX(hbox1), hbox2, FALSE, FALSE, 0);

        gtk_widget_show_all(win);
        gtk_main();
        return 0;
}




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