c - Problems with very simple GtkTextView use case -



c - Problems with very simple GtkTextView use case -

i'm having gtk+ 3.0 ui designed glade , implemented in c 2 list view (implmented gtktreeview). when click on 1 item in sec list view want details of entry displayed in multi line text view. there no other selection using gtktextview, though need maybe less 1% of gtktextview provides (i don't need edit). however, having gtktextview element on ui programme crashes @ first clicks on list. when remove updating of gtktextview code, can play around eternally ui, no crash ever. here code updates text view:

// stuff list store gtk_tree_model_get_iter (gtk_tree_model (liststore), &iter, tree_path); gtk_tree_model_get (gtk_tree_model (liststore), &iter, item_name, &itemname, item_desc, &itemdesc, item_link, &itemlink, -1); // fill couple of 1 line gtkentry first // ... // fill text view txtbuffer = gtk_text_view_get_buffer (gtk_text_view (txtdesc)); gtk_text_buffer_set_text (txtbuffer, itemdesc, -1);

i've checked itemdesc non-null. i've analyzed valgrind , funny thing no obvious memory handling error detected stack overflow! i'm using recursion... anyway, here's valgrind output:

==4879== stack overflow in thread 1: can't grow stack 0xffe801ff8 ==4879== ==4879== process terminating default action of signal 11 (sigsegv) ==4879== access not within mapped part @ address 0xffe801ff8 ==4879== @ 0x5b36564: g_hash_table_lookup (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4000.0) ==4879== if believe happened result of stack ==4879== overflow in program's main thread (unlikely ==4879== possible), can seek increment size of ==4879== main thread stack using --main-stacksize= flag. ==4879== main thread stack size used in run 8388608. ==4879== ==4879== heap summary: ==4879== in utilize @ exit: 3,946,706 bytes in 45,434 blocks ==4879== total heap usage: 326,942 allocs, 281,508 frees, 25,249,132 bytes allocated ==4879== ==4879== leak summary: ==4879== lost: 3,664 bytes in 32 blocks ==4879== indirectly lost: 12,977 bytes in 542 blocks ==4879== perchance lost: 165,544 bytes in 1,342 blocks ==4879== still reachable: 3,594,265 bytes in 42,477 blocks ==4879== suppressed: 0 bytes in 0 blocks ==4879== rerun --leak-check=full see details of leaked memory ==4879== ==4879== counts of detected , suppressed errors, rerun with: -v ==4879== error summary: 0 errors 0 contexts (suppressed: 0 0)

any thought appreciated. here's c code.

#include <gtk/gtk.h> #include <string.h> #include <glib.h> #include <libxml/parser.h> #include <sqlite3.h> #include "kpodcast.h" #include "global.h" gtkbuilder *builder; enum { podcast_name = 0, ncolumns }; enum { item_name = 0, item_date = 1, item_desc = 2, podcast_idx = 3, item_link = 4, ncolumns2 }; extern glist * all_podcasts; extern gtimezone * gtimezone; extern sqlite3 * db; void kleine_callback (gtkwidget *w, gpointer d) { gtkwidget *dialog; dialog = gtk_message_dialog_new (null, gtk_dialog_destroy_with_parent, gtk_message_info, gtk_buttons_close, "hallo, welt!"); gtk_dialog_run (gtk_dialog (dialog)); gtk_widget_destroy (dialog); } void on_item_selection_change (gtktreeselection * widget, gpointer user_data) { glist * selection = gtk_tree_selection_get_selected_rows (widget, null); gtktreepath * tree_path = null; gtklabel * txtdesc = null; gtkentry * txtlink = null; gtktextbuffer* txtbuffer = null; gtkentry * txtname = null; gtkliststore * liststore = null; char * message = null; gtktreeiter iter; gchar * itemname = null; gchar * itemdesc = null; gchar * itemlink = null; gtkstatusbar * status_bar = gtk_widget (gtk_builder_get_object (builder, "status_bar")); txtname = gtk_widget (gtk_builder_get_object (builder, "txtitemname")); txtdesc = gtk_widget (gtk_builder_get_object (builder, "txtitemdesc")); txtlink = gtk_widget (gtk_builder_get_object (builder, "txtitemlink")); if (selection != null) { tree_path = (gtktreepath *) selection->data; int depth = gtk_tree_path_get_depth (tree_path); int * idx = gtk_tree_path_get_indices (tree_path); liststore = gtk_list_store (gtk_builder_get_object (builder, "liststore_podcast_items")); gtk_tree_model_get_iter (gtk_tree_model (liststore), &iter, tree_path); gtk_tree_model_get (gtk_tree_model (liststore), &iter, item_name, &itemname, item_desc, &itemdesc, item_link, &itemlink, -1); // set item name gtk_entry_set_text (txtname, itemname); //gtk_label_set_text (txtdesc, itemdesc); // set item description txtbuffer = gtk_text_view_get_buffer (gtk_text_view (txtdesc)); gtk_text_buffer_set_text (txtbuffer, itemdesc, -1); // set item link gtk_entry_set_text(txtlink, itemlink); free_pointer1 (itemname); free_pointer1 (itemdesc); free_pointer1 (itemlink); } else { gtk_entry_set_text (txtname, ""); gtk_entry_set_text (txtlink, ""); /* txtbuffer = gtk_text_view_get_buffer (gtk_text_view (txtdesc)); gtk_text_buffer_set_text (txtbuffer, "", -1); */ gtk_label_set_text (txtdesc, itemdesc); } } void on_podcast_selection_change (gtktreeselection *widget, gpointer user_data) { glist * selection = gtk_tree_selection_get_selected_rows (widget, null); gtktreepath * tree_path = null; char * message = null; gtkstatusbar * status_bar = gtk_widget (gtk_builder_get_object (builder, "status_bar")); guint context = gtk_statusbar_get_context_id (status_bar, "some_context_id"); kpodcastptr podcast = null; gtkliststore * liststore = null; gtktreeiter iter; guint item_list_length = 0, jj=0; if (selection) { tree_path = (gtktreepath *) selection->data; int depth = gtk_tree_path_get_depth (tree_path); if (depth == 1) { // replace assert (depth = 1) //set gtktreeiter index // add together name , description ui // int * idx = gtk_tree_path_get_indices (tree_path); podcast = (kpodcastptr) g_list_nth_data (all_podcasts, *idx); /* gtk_entry_set_text(txtname, podcast->name); txtbuffer = gtk_text_buffer_new (null); gtk_text_buffer_set_text (txtbuffer, podcast->desc, -1); gtk_text_view_set_buffer(txtdesc, txtbuffer); */ // // list store // liststore = gtk_list_store (gtk_builder_get_object (builder, "liststore_podcast_items")); gtk_list_store_clear (liststore); // // add together podcasts // item_list_length = g_list_length (podcast->items); (jj=0; jj<item_list_length; jj++) { kpodcastitemptr item = (kpodcastitemptr) g_list_nth_data (podcast->items, jj); gdatetime * gdate = null; char * date; gdate = g_date_time_new_from_unix_local (item->pubdate); date = g_date_time_format (gdate, "%y-%m-%d"); gtk_list_store_append(liststore, &iter); gtk_list_store_set (liststore, &iter, item_name, item->name, item_date, date, item_desc, item->desc, podcast_idx, *idx, item_link, item->link, -1); g_date_time_unref (gdate); } } } else { message = g_strdup ("treepath null."); gtk_statusbar_push (status_bar, context, message); //g_printf ("statusbar force returned %d.\n", rc); g_free (message); } g_list_free_full (selection, (gdestroynotify) gtk_tree_path_free); } void on_action_add_podcast (gtkwidget * widget, gpointer user_data) { gtkstatusbar * status_bar = gtk_widget (gtk_builder_get_object (builder, "status_bar")); if (status_bar == null) printf ("no status bar.\n"); else { guint context = gtk_statusbar_get_context_id (status_bar, "somectxt"); char * message = g_strdup ("add_podcast clicked."); guint rc = gtk_statusbar_push (status_bar, context, message); g_free (message); } } void on_action_click_download (gtkwidget * widget, gpointer user_data) { gtkstatusbar * status_bar = gtk_widget (gtk_builder_get_object (builder, "status_bar")); if (status_bar == null) printf ("no status bar.\n"); else { guint context = gtk_statusbar_get_context_id (status_bar, "somectxt"); char * message = g_strdup ("podcast download clicked."); guint rc = gtk_statusbar_push (status_bar, context, message); g_free (message); } } void on_button_test_clicked (gtkwidget * w, gpointer d) { g_print ("on button test clicked!"); } void quit (gtkwidget * w, gpointer d) { gtk_main_quit (); } #ifdef gtkui int main (int argc, char *argv[]) #else int main_ (int argc, char *argv[]) #endif { gerror * error = null; gtkwidget * window; gtkliststore * liststore_podcast; gtktreeiter iter; // // init podcast stuff // // db if (!init_db ()) { printf ("db not initialized: %s.", sqlite3_errmsg (db)); homecoming 0; } // timezone gtimezone = g_time_zone_new_local (); // init podcasts if (!init_podcasts ()) { printf ("podcasts not initialized, leaving."); homecoming 0; } // // gtk+ stuff // gtk_init (&argc, &argv); builder = gtk_builder_new (); if (!gtk_builder_add_from_file (builder, "kaixn.glade", &error)) { g_warning ("%s", error->message); g_free (error); homecoming 1; } liststore_podcast = gtk_list_store (gtk_builder_get_object (builder, "liststore_podcasts")); if (liststore_podcast) { int ll = g_list_length (all_podcasts); if (ll == 0) { printf ("podcast list empty.\n"); } else { int idx = 0; (idx = 0; idx < ll; idx++) { kpodcastptr podcast = (kpodcastptr) g_list_nth_data (all_podcasts, idx); /* append empty row list store. iter point new row */ gtk_list_store_append(liststore_podcast, &iter); gtk_list_store_set (liststore_podcast, &iter, podcast_name, podcast->name, -1); } } } else { g_print ("couldn't liststore_podcasts.\n"); } window = gtk_widget(gtk_builder_get_object (builder, "main_window")); gtk_builder_connect_signals (builder, null); gtk_widget_show_all (window); gtk_main (); homecoming 0; }

many kai

c gtk glade

Comments

Popular posts from this blog

c# - ASP.NET MVC Sequence contains no matching element -

java - Parsing XML, skip certain tags -

rest - How to invalidate user session on inactivity in a stateless server? -