Re: gdk_threads_leave is possible to cause segmentation fault?

2017-03-28 Thread Rúben Rodrigues
Thanks!
So i could replate enter and leave to g_iddle_add, right?

gdk_threads_enter();
 g_printf("UpdateConfigNow\n");
 iUpdateConfigNow();
gdk_threads_leave();

To

g_idle_add((GCallback)iUpdateConfigNow, NULL);

Why i get this error?

Main.c:1824: undefined reference to `g_iddle_add'

Thanks


Às 11:49 de 28/03/2017, Gabriele Greco escreveu:

In gdk manual i see thath gdk_threads_enter and leave has been
deprecated and alll gdk and gtk+ calls should be made from main thread.
How we do this? Someone have any example?

You have to call g_idle_add (that is thread safe) every time you need to update 
one or more widgets from an external thread.

Let's think about a common situation, for instance you are encoding a video 
file and you want to update a progress bar:

[from encoding thread]
struct progress {
char label[50];
float value;
};

myprg = malloc(sizeof(struct progress));
myprg->value = 75.0;
strncpy(myprg->label, "Second pass", sizeof(myprg->label));
g_idle_add((GCallback)progress_update, myprg);

gboolean progress_update(struct progress *p);
{
 gtk_progress_bar_set_text(p->label);
 gtk_progress_bar_set_fraction(p->value);
 free(p);
 return FALSE; // it means that you want to run this only once
}

--
Bye,
 Gabry


[https://ipmcdn.avast.com/images/icons/icon-envelope-tick-round-orange-animated-no-repeat-v1.gif]
  Sem vírus. 
www.avast.com
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: gdk_threads_leave is possible to cause segmentation fault?

2017-03-28 Thread Gabriele Greco
> But  now this functions aren't running. This is my main thread
> void *vGtkMain_Thread(gpointer data)
> {
> gdk_threads_enter();
> gtk_main();
> gdk_threads_leave();
> return NULL;
> }
>

You should remove everywhere in your code gtk_threads_ calls.

You cannot call gtk_label_get_text from a thread different from the gtk
main loop one, get the result of the call and pass it to the thread
function as parameter.

You should take care that the functions you call with g_idle_add() return
FALSE otherwise they will be called every time the main loop is idle using
100% of CPU (this can be a desired behaviour in some circumstances).

You should also take care that the global data you access in
iUpdateConfigNow, gbUpdateStatusNow... is not changed while you are
updating the GUI


-- 
*Bye,*
* Gabry*
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: gdk_threads_leave is possible to cause segmentation fault?

2017-03-28 Thread Gabriele Greco
>
>
> In gdk manual i see thath gdk_threads_enter and leave has been
> deprecated and alll gdk and gtk+ calls should be made from main thread.
> How we do this? Someone have any example?
>
> You have to call g_idle_add (that is thread safe) every time you need to
update one or more widgets from an external thread.

Let's think about a common situation, for instance you are encoding a video
file and you want to update a progress bar:

[from encoding thread]
struct progress {
char label[50];
float value;
};

myprg = malloc(sizeof(struct progress));
myprg->value = 75.0;
strncpy(myprg->label, "Second pass", sizeof(myprg->label));
g_idle_add((GCallback)progress_update, myprg);

gboolean progress_update(struct progress *p);
{
 gtk_progress_bar_set_text(p->label);
 gtk_progress_bar_set_fraction(p->value);
 free(p);
 return FALSE; // it means that you want to run this only once
}

-- 
*Bye,*
* Gabry*
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


gdk_threads_leave is possible to cause segmentation fault?

2017-03-28 Thread Rúben Rodrigues
Hi guys,

My application sometimes have segmentation fault error. In debug mode 
and using g_print() i see that the applications stops in 
gdk_thread_leave function.

In gdk manual i see thath gdk_threads_enter and leave has been 
deprecated and alll gdk and gtk+ calls should be made from main thread. 
How we do this? Someone have any example?

Thanks!


___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list