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


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 gmail com> wrote:


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,


16.9.2015 7.03 "Lokesh Chakka" <lvenkatakumarchakka gmail com> kirjoitti:

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 <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 );
    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 );

int main()
    pthread_t th;

    gtk_init( NULL, NULL );

    main_window = (GtkWindow*)gtk_window_new(GTK_WINDOW_TOPLEVEL);

    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 );

    return 0;

Thanks & Regards
Lokesh Chakka,
Mobile: 9731023458

gtk-devel-list mailing list
gtk-devel-list gnome org

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]