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 Nov 26, 2014 11:02 pm

All times are UTC




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: segmentation fault on gtk_widget_destroy
PostPosted: Sat Apr 26, 2008 2:09 am 
Offline
Familiar Face

Joined: Fri Feb 29, 2008 6:00 pm
Posts: 7
Hi,

My GTK application is involved with creating a table of x rows and y columns. This table added to the toplevel window as

gtk_container_add (GTK_CONTAINER (window), table);
gtk_widget_show_all (window);

My "update" function retrieves data and controls display from above table. At some later time during the update, I want to have a total different display which I need to destroy current table and create a new table of different size of rows and columns.

gtk_widget_destroy (GTK_WIDGET (table));
table = gtk_table_new (newrow, newcol, FALSE);

I got a segmentation fault at the "gtk_widget_destroy" call. How do I resolve this situation ? Please help.

ctran


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 26, 2008 4:44 am 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
Could you post a little bit more code? We can't see what's going on in the update function ...

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 26, 2008 12:16 pm 
Offline
Familiar Face

Joined: Fri Feb 29, 2008 6:00 pm
Posts: 7
Right now I used time to change display page but later will link to shared memory where I rely on some variable change to change this display page.

The segmentation fault occurred when changing to special page.

gint
update(gpointer data)
{
...
gettimeofday(&t_now, NULL);
deltat = (t_now.tv_sec - t_prev.tv_sec)*1000 +
(t_now.tv_usec - t_prev.tv_usec + 500)/1000;

if (deltat > 15000 && !set_special_page) {
create_special_page();
set_special_page = 1;
special_page = 1;
}

if (deltat > 30000 && !set_regular_page) {
create_regular_page();
set_regular_page = 1;
special_page = 0;
}
...
}

void
create_regular_page()
{
if(table) {
gtk_widget_destroy(GTK_WIDGET(window), table);
table = gtk_table_new(16, 3, FALSE);
....
}
}

void
create_special_page()
{
if(table) {
gtk_widget_destroy(GTK_WIDGET(window), table);
table = gtk_table_new(33, 8, FALSE);
....
}
}

int
main (int argc,
char *argv[])
{
...

create_regular_page();

gtk_container_add (GTK_CONTAINER (window), table);
gtk_widget_show_all (window);

gettimeofday(&t_prev, NULL);
timer = g_timeout_add(1000, update, hdr_ebox);

gtk_main ();
return 0;
}


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 26, 2008 2:59 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
First, gtk_widget_destroy() takes a single parameter. You are destroying your window and then recreating the table. Second, how are you passing the table to the function? You might want to read this post: http://www.gtkforums.com/viewtopic.php?p=2933

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 26, 2008 3:21 pm 
Offline
Familiar Face

Joined: Fri Feb 29, 2008 6:00 pm
Posts: 7
Sorry, I typed it wrong when I posted because I had this in my code

gtk_widget_destroy (GTK_WIDGET (top_table));

Just simply rename as table instead of top_table.

Everything else is the same.

My window, table variables are declared as global, above all functions and main.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 26, 2008 4:17 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
When in the code is this table every created initially? The first time you call gtk_widget_destroy(), it is on an invalid memory location.

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 26, 2008 4:36 pm 
Offline
Familiar Face

Joined: Fri Feb 29, 2008 6:00 pm
Posts: 7
The call to create_regular_page in main created the table the first time. Since this table variable is defined globally, it should be defined in create_special_page. I put down some printf statements and the regular page worked fine and after 15 secs I got seg fault when calling special page. It failed at gtk_widget_destroy.

You think I should define variables locally and pass them to functions ?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 27, 2008 12:31 am 
Offline
Familiar Face

Joined: Fri Feb 29, 2008 6:00 pm
Posts: 7
One thing I have for the regular page that I connect a signal to an expose event to do some drawing (line, arrow, etc.) while updating. So by destroying the table like this it caused some problem. I will look again in my codes.

I wrote a much simpler example with 5x1 table with label widgets created first time and later destroy it and recreated with 2x1 table and it worked fine.

If I need to handle anything special for event prior to destroying the table, please let me know. Thanks for your help.


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

All times are UTC


Who is online

Users browsing this forum: Yahoo [Bot] and 2 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