Re: Debian 6 with Sudden GTK application crash @ libGDK
- From: venkat <venkat s vortexindia co in>
- To: Chris Vine <chris cvine freeserve co uk>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: Debian 6 with Sudden GTK application crash @ libGDK
- Date: Wed, 10 Dec 2014 17:31:46 +0530
Chris
Thanks for the feedbacks.
Nearby, future we are sure we will migrate to G_IDLE_ADD.
Just started to code wit GTK.  Could please guide some points for below.
We are trying to convert our GTK application from GDK_THREAD -- ENTER() 
/ LEAVE() to G_timeout or G_idle.
With the sample implementation, I have 2 problems.
Problem 1:
    G_TIMEOUT_ADD(dispTextPage), the application works as expected. 
But, a steady memory growth of 128K per minutes is seen in XORG.
    When i run through my code flow I am not able to point any error
Problem 2:
    When i try to run G_IDLE_ADD(dispTextPage1) i notice the 
application does not works as expected.I don't see continuous screen toggle.
    **what are all the scenarios i should use G_TIMEOUT_ADD and 
G_IDLE_ADD. request guidance
Below shown is the sample implementation.
    #include <gtk/gtk.h>
    #include <string.h>
    #include <stdio.h>
    #include <pthread.h>
    #include<stdlib.h>
    #define DELAY_PRE_DISP 50
    #define DELAY_POST_DISP 1000
    typedef struct {
    char* fileName;
    }dispTextPage_struct;
    static int waitForLoop = 0;
    GtkWidget *window;
    pthread_t fsmThreadId;
    void destroyWidget(int index)
    {
        GList *children, *iter;
        children = gtk_container_get_children(GTK_CONTAINER(window));
        for(iter = children; iter != NULL; iter = g_list_next(iter)){
gtk_container_remove(GTK_CONTAINER(window),GTK_WIDGET(iter->data));
            printf("Deleting Widget\n");
        }
            g_list_free(iter);
            g_list_free(children);
    }
    int dispTextPage_callBack(dispTextPage_struct *params)
    {
        char* fileName = params -> fileName;
        GtkWidget *layout;
        GtkWidget *image;
        printf("Call back - DW\n");
        destroyWidget(1);
        printf("Call back - DW1\n");
        layout = gtk_layout_new(NULL, NULL);
        gtk_container_add(GTK_CONTAINER (window), layout);
        gtk_widget_show(layout);
        image = gtk_image_new_from_file(fileName);
        gtk_layout_put(GTK_LAYOUT(layout), image, 0, 0);
        gtk_widget_show_all(window);
        free(params);
        return 0;
    }
    int destroyNotify(void)
    {
        while (gtk_events_pending())
        {
            g_usleep (100);
            gtk_main_iteration_do(FALSE);
        }
        waitForLoop = 0;
    //    printf ("dddddddddddddd");
        return 0;
    }
    int dispTextPage(char* tempfileName, int pixBufOperation)
    {
        printf("Calling started\n");
        dispTextPage_struct *params;
        char fileName[256];
        printf("Calling started SET\n");
        memset(fileName,0,sizeof(fileName));
        strcpy(fileName,tempfileName);
        params = (dispTextPage_struct*)malloc(sizeof(dispTextPage_struct));
        params->fileName = fileName;
        (void)g_timeout_add(33, (GSourceFunc)dispTextPage_callBack, 
params);
        return 0;
    }
    int dispTextPage1(char* tempfileName, int pixBufOperation)
    {
        printf("Calling started\n");
        dispTextPage_struct *params;
        char fileName[256];
        printf("Calling started SET\n");
        memset(fileName,0,sizeof(fileName));
        strcpy(fileName,tempfileName);
        params = (dispTextPage_struct*)malloc(sizeof(dispTextPage_struct));
        params->fileName = fileName;
        while(waitForLoop == 1) usleep(DELAY_PRE_DISP);
        waitForLoop=1;
g_idle_add_full(G_PRIORITY_DEFAULT_IDLE,dispTextPage_callBack,params,destroyNotify);
        while(waitForLoop == 1) usleep(DELAY_POST_DISP);
        return 0;
    }
    void *fsmThread_RunFunction(void *threadid)
    {
        sleep(4);
        while (1)
        {
        system("echo 000.gif >> logme.txt");
        printf("Calling 000.gif\n");
        dispTextPage("000.gif",0);
        sleep(1);
        system("echo 001.gif >> logme.txt");
        printf("Calling 001.gif\n");
        dispTextPage("001.gif",1);
        sleep(1);
        //dispTextPage1("001.gif",1);
        //sleep(1);
        }
    }
    int main (int argc, char **argv)
    {
        GError *error = NULL;
        size_t stacksize;
        pthread_attr_t attr;
        long t=1;
        printf("fsmThreadId");
        gtk_init (&argc, &argv);
        g_thread_init(NULL);
        gdk_threads_init();
        //gdk_threads_enter();
        window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
        gtk_window_resize((GtkWindow*)window, 800, 600);
        gtk_widget_realize( window );
        gtk_window_set_decorated((GtkWindow*)window, FALSE);
        g_thread_create(main_callback, NULL, FALSE, NULL);
        gtk_window_set_decorated((GtkWindow*)window, FALSE);
        pthread_attr_init(&attr);
        pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
        pthread_attr_getstacksize (&attr, &stacksize);
        stacksize = sizeof(char)*10*1024*1024;
        pthread_attr_setstacksize (&attr, stacksize);
        if( pthread_create(&fsmThreadId, &attr, fsmThread_RunFunction, 
(void *)t) )
        {
            exit(-1);
        }
        printf("fsmThreadId created");
        gtk_main();
        if(pthread_join(fsmThreadId, NULL))
        {
        exit(-1);
        }
    }
On 09-12-2014 15:54, Chris Vine wrote:
On Tue, 09 Dec 2014 13:11:59 +0530
venkat <venkat s vortexindia co in> wrote:
[snip]
--
Regards
Venkat.S
[
Date Prev][
Date Next]   [
Thread Prev][
Thread Next]   
[
Thread Index]
[
Date Index]
[
Author Index]