GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Wed Oct 22, 2014 4:49 am

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Segfault when creating treeview with my tree model filter
PostPosted: Sun Jan 27, 2013 10:07 pm 
Offline
Familiar Face

Joined: Mon Jan 14, 2013 9:30 pm
Posts: 5
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.


Top
 Profile  
 
 Post subject: Re: Segfault when creating treeview with my tree model filte
PostPosted: Mon Jan 28, 2013 6:44 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 764
Location: UK
Hi,

What you are doing is passing around a pointer, in this case list_inter, that is not initialised and points to a random area of memory. This is your cause of the segmentation fault.

GtkTreeIter is a normal structure, is not derived from anything else and can be set up in the usual way.

This is how to create your GtkTreeIter
Code:
GtkTreeIter list_iter; // Note this is not a pointer

This is how to use your GtkTreeIter
Code:
gtk_tree_model_get_iter_first(list_model, &list_iter); // We take the address of list_iter

_________________
E.


Top
 Profile  
 
 Post subject: Re: Segfault when creating treeview with my tree model filte
PostPosted: Mon Jan 28, 2013 6:51 am 
Offline
Familiar Face

Joined: Mon Jan 14, 2013 9:30 pm
Posts: 5
errol wrote:
Hi,

What you are doing is passing around a pointer, in this case list_inter, that is not initialised and points to a random area of memory. This is your cause of the segmentation fault.

GtkTreeIter is a normal structure, is not derived from anything else and can be set up in the usual way.

This is how to create your GtkTreeIter
Code:
GtkTreeIter list_iter; // Note this is not a pointer

This is how to use your GtkTreeIter
Code:
gtk_tree_model_get_iter_first(list_model, &list_iter); // We take the address of list_iter


You know, I'm having one of those face-palm moments where I feel really dumb, I should have realized that, I don't know how I overlook some of these things sometimes -_- Anyways, thanks a bunch for pointing that out, I really appreciate the help! :D


Top
 Profile  
 
 Post subject: Re: Segfault when creating treeview with my tree model filte
PostPosted: Mon Jan 28, 2013 6:53 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 764
Location: UK
This one is always a one to get many people. Nearly everything in GTK+ you initialise with a function it is always a pointer. This is one of those few cases where it is not.

_________________
E.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group