Odd segfault



GTK newbie here.  In writing some sample code, I'm getting some odd
behavior I can't quite grasp.  Here's a snippet of the code:

---------------- cut ----------------------
void file_ok_sel(GtkWidget *widget, struct holdbuffer *hb)
{
    hb->cmdfile = g_strdup(gtk_file_selection_get_filename
(GTK_FILE_SELECTION (hb->fsel)));
    gtk_main_quit();
}

/* select a file to open */
void selectfile(struct holdbuffer *hbuf, gchar *type)
{
    GtkWidget *fsel;
    gchar *title = g_strconcat("Select a ", type);
    gchar *fnam;

    hbuf->fsel = gtk_file_selection_new( title  );

    g_signal_connect (G_OBJECT (fsel), "destroy",
            G_CALLBACK (gtk_main_quit), NULL);
    g_signal_connect (G_OBJECT (GTK_FILE_SELECTION
(hbuf->fsel)->ok_button),
            "clicked", G_CALLBACK (file_ok_sel), hbuf);
    g_signal_connect_swapped(G_OBJECT(GTK_FILE_SELECTION(hbuf->fsel)->cancel_button),
     
            "clicked", G_CALLBACK (gtk_widget_destroy),
            G_OBJECT (hbuf->fsel));
    gtk_widget_show (hbuf->fsel);
    gtk_main();
    g_free(title);
    gtk_widget_destroy(GTK_WIDGET(hbuf->fsel));
    g_free(fnam);
}
    
/* Callback for file selection */
static void get_filename(struct holdbuffer *hbuf, guint action,
GtkWidget *widget)
{
    switch (action) {
        case 1: /* cmd file */
MAGIC LINE ----> g_print(<something>);
            selectfile(hbuf, "Command file");
            g_print("You picked %s\n",hbuf->cmdfile);
            break;

----------------- cut ----------------------

OK..  Of course, there's more, but I think this summarizes it.  It's set
up with ItemFactory, and all this seems to work.

However, note the "MAGIC LINE" above.  If I have this line inserted
here, it works, but if simply remove this line, and do nothing else, I
get a segfault. Why would the absence of this line cause such, and the
presence prevent it?  If it has anything to do with it, here's the
definitions for the hbuf stuff..

struct holdbuffer {
    gchar *cmdfile;
    GtkWidget *fsel;
} HoldBuf;

and, this, if it might have something to do with it..

gtk_item_factory_create_items (menu_bar, nmenu_items,
            menu_items, &HoldBuf);

The answer may be something quite simple, but I'm completely baffled by
the nature of it.




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