GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sat Oct 25, 2014 7:41 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: [SOLVED] Updating image gives strange patterns.
PostPosted: Wed May 22, 2013 9:12 am 
Offline

Joined: Tue May 21, 2013 9:15 pm
Posts: 4
I bet i have some kind of memory problem here; not sure what the origin is. I have a GUI that has three images side by side. When i press a button to load in a new image, it creates a detached pthread and puts that image into image box 1; before that, the image from box 1 went to box 2, and that of 2 went into image box 3 (and the image in box 3 is discarded).
The thing is that i can load in an image perfectly fine, but when moving the images from box 2 to 3 and 1 to 2 things go bad. The images are corrupted, they just look like colorful static 'snow'.

What i do: i define the three boxes outside of the main-loop
Code:
GtkWidget *guiImage1,*guiImage2,*guiImage3


Then inside of the main-loop i create that pthread, where i create 3 dummy images first:
Code:
gtk_image_new_from_pixbuf (... etc)
.

From the pthread i load the new image somehwere and i go into this:
Code:
//First put 2 in 3, then 1 in 2. Then update 1.
gtk_image_set_from_pixbuf( GTK_IMAGE(guiImage3), gtk_image_get_pixbuf( GTK_IMAGE(guiImage2) ) );
gtk_image_set_from_pixbuf( GTK_IMAGE(guiImage2), gtk_image_get_pixbuf( GTK_IMAGE(guiImage1) ) );
gtk_image_set_from_pixbuf( GTK_IMAGE(guiImage1), MatToPixbuf(matGUI) );

After this, the pthread ends nicely, and i can repeat the process.

Now what always happens is that the first image box displays the image fine, but the 2nd and 3rd are corrupted, as i said earlier. What is happening here? Should i allocate the pixbuf's 'globally' as well?
[Using GTK-2.? in C++]


Last edited by timbobel on Fri May 24, 2013 6:40 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Updating image gives strange patterns.
PostPosted: Thu May 23, 2013 6:31 am 
Offline
Never Seen the Sunlight

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

With the little information you have given I would take a guess that you have memory corruption due to incorrect use of threads. GTK+ is thread aware, but not thread safe. You will need to take precautions when using threads for example using the GDK global lock or to place all access to GTK/GDK to the main thread only.

_________________
E.


Top
 Profile  
 
 Post subject: Re: [SOLVED] Updating image gives strange patterns.
PostPosted: Fri May 24, 2013 6:41 pm 
Offline

Joined: Tue May 21, 2013 9:15 pm
Posts: 4
The answer is that i did not save the pixelbuffer. It turned out i had to make sure the pixelbuffer lived as least as long as the gtkimage lived. Solution was simple, assign the pixelbuffer globally as well, or in my case, an openCV cv::Mat that i kept in tact.


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

All times are UTC


Who is online

Users browsing this forum: No registered users 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