Web lists-archives.com

Re: GLib-CRITICAL Source ID 35 was not found when attempting to remove it




markku,

i kept gtk_thread_enter / leave for experimental purpose.
Actually issue was happening irrespective of existence of gtk_thread_enter / leave.

Thanks & Regards
--
Lokesh Chakka,
Mobile: 9731023458

On Wed, Sep 16, 2015 at 10:21 AM, markku vire <markku.vire@xxxxxxxxx> wrote:

Hi,

Nowadays gdk_threads_enter ()/leave () are deprecated, so you should not use them in newly written code. You need to do gtk calls from main thread instead. You can send notifications to main thread easily using g_idle_add, which schedules them to happen on next main loop iteration.

When working with older versions of gtk, you need to acquire gdk lock before doing any gtk call from background thread. So, you should move threads_enter/leave around queue_draw in your thread_function.

Hope this helps,

-Markku-

16.9.2015 7.03 "Lokesh Chakka" <lvenkatakumarchakka@xxxxxxxxx> kirjoitti:
hello,

I have written small piece of code and I am seeing thread_function is getting stuck. If I try to close the window, I am seeing GLib Critical error

Can some body please help me fixing the issue ?

following is the code:

#include<gtk/gtk.h>
#include<cairo.h>
#include<stdlib.h>
#include <pthread.h>

GtkDrawingArea *darea;
GtkVBox  *main_window_box;
GtkWindow    *main_window;

const int size = 500;
int i;

static void my_draw_event( GtkWidget *widget, cairo_t *cr, void *parameter )
{
    int a, b;
    cairo_set_source_rgb( cr, 1, 0, 0 );
    a = random()%size;
    b = random()%size;
    cairo_move_to( cr, a, a );
    cairo_line_to( cr, b, b );
    cairo_stroke(cr);
    gtk_widget_show_all((GtkWidget*)main_window);
    fprintf( stderr, "Values i: %4d a: %3d b: %3d\n", i, a, b );
}

static void *thread_function( void *parameter )
{
    const int seconds = 1000;

    for( i=0; i<seconds; i++ )
    {
        gtk_widget_queue_draw( (GtkWidget*)darea );
        sleep(1);
    }
}

int main()
{
    pthread_t th;

    gdk_threads_init();
    gdk_threads_enter();
    gtk_init( NULL, NULL );

    main_window = (GtkWindow*)gtk_window_new(GTK_WINDOW_TOPLEVEL);
    g_signal_connect(G_OBJECT(main_window),"destroy",G_CALLBACK(gtk_main_quit),NULL);

    main_window_box = (GtkVBox*)gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
    gtk_container_add (GTK_CONTAINER (main_window),(GtkWidget*)main_window_box);

    darea = (GtkDrawingArea*)gtk_drawing_area_new();
    gtk_box_pack_start( GTK_BOX( main_window_box ), (GtkWidget*)darea, TRUE, TRUE, 0 );
    g_signal_connect( G_OBJECT(darea), "draw", G_CALLBACK( my_draw_event ), NULL );

    gtk_window_set_position(GTK_WINDOW(main_window), GTK_WIN_POS_CENTER);
    gtk_window_set_default_size(GTK_WINDOW(main_window), size, size );

    pthread_create( &th, NULL, thread_function, NULL );
    gtk_widget_show_all((GtkWidget*)main_window);
    gtk_main();
    gdk_threads_leave();

    return 0;
}

Thanks & Regards
--
Lokesh Chakka,
Mobile: 9731023458

_______________________________________________
gtk-devel-list mailing list
gtk-devel-list@xxxxxxxxx
https://mail.gnome.org/mailman/listinfo/gtk-devel-list


_______________________________________________
gtk-devel-list mailing list
gtk-devel-list@xxxxxxxxx
https://mail.gnome.org/mailman/listinfo/gtk-devel-list