I'm working on an app with GTK3 in C, here is the issue I'm having:
I have a tree model that is being filtered with GtkTreeModelFilterVisibleFunc, it was working perfectly fine until I added something to my filter function. I added:
Code:
GtkTreeModel *list_model = gtk_tree_view_get_model(GTK_TREE_VIEW(library_view));
GtkTreeIter *list_iter; // If I say *list_iter = NULL it doesn't segfault
gchar *selected_list;
GtkTreeSelection *list_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(library_view));
if(gtk_tree_selection_get_selected(list_selection, NULL, list_iter) == TRUE) {
gtk_tree_model_get(list_model, list_iter, 0, selected_list, -1);
printf("%s\n", selected_list);
}
else {
gtk_tree_model_get_iter_first(list_model, list_iter); // When list_iter == NULL this fails, but app doesn't sefault
gtk_tree_model_get(list_model, list_iter, 0, &selected_list, -1);
printf("SELECTED LIST: %s\n", selected_list); // When list_iter == NULL this prints (null) instead of the correct value,
//however when I don't initialize list_iter to NULL, it successfully prints the correct value,
//and my filter function returns fine, but then it segfaults when creating treeview
}
If I remove this it works fine, however I need to get the selected item from library_view (or the first item), to finish up my filter function. It successfully prints the correct value with printf("SELECTED LIST: %s\n", selected_list);, it doesn't crash in the filter function.
Here is my backtrace with gdb:
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff3c00747 in ?? () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
(gdb) backtrace
#0 0x00007ffff3c00747 in ?? () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#1 0x00007ffff3c00d89 in g_sequence_append ()
from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#2 0x00007ffff7648f22 in ?? () from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#3 0x00007ffff7649e89 in ?? () from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#4 0x00007ffff7669257 in gtk_tree_view_set_model ()
from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#5 0x00007ffff6f6ea6c in g_object_newv ()
from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#6 0x00007ffff6f6f040 in g_object_new_valist ()
from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#7 0x00007ffff6f6f374 in g_object_new ()
from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#8 0x0000000000405839 in gui_SetupRightPane (conf=0x7fffffffe0c0) at gui.c:436
Line 436 is this: GtkWidget *series_view = gtk_tree_view_new_with_model(series_filter);
series_filter is the filter that uses the filter function in question, so like I said, if I remove that code block I posted from my filter function it works fine, also if I initialize list_iter to NULL, it also doesn't crash, however it fails to get the iter because list_iter can't be initialized to NULL, and it prints (null) instead of the selected item (or first item if none selected) from library_view, so failing to get list_iter will keep it from crashing when creating the treeview with series_filter, however successfully getting list_iter (having the filter function succeed and print the correct value, and return TRUE successfully) causes my app to segfault when creating the treeview with series_filter.
I hope my question makes sense, and I really apprecieate any help, this is really getting frustrating.