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

g_threads problem.



Hello,

I have got a problem.  I get the following error:


** (gports:47984): WARNING **: Invalid UTF8 string passed to 
pango_layout_set_text()
The program 'gports' received an X Window System error.
This probably reflects a bug in the program.
The error was 'BadRequest (invalid request code or no such operation)'.
   (Details: serial 39922 error_code 1 request_code 229 minor_code 0)
   (Note to programmers: normally, X errors are reported asynchronously;
    that is, you will receive the error a while after causing it.
    To debug your program, run it with the --sync command line
    option to change this behavior. You can then get a meaningful
    backtrace from your debugger if you break on the gdk_x_error() 
function.)

But I think (not really sure) I'm doing everything correct.

I attached the file I use for this.  The main things are:

void update_ports_treestore (void)
{
   GThread* thread;
     if (gports_search.running == TRUE)
     gports_search.stop = TRUE;
       if (!g_thread_supported ()) g_thread_init (NULL);
   thread = g_thread_create ((gpointer) update_ports_treestore_run,
                             NULL, TRUE, NULL);
}

That should be correct.  In the function update_ports_treestore_run I 
have at the beginning:

static GStaticMutex mutex_lock = G_STATIC_MUTEX_INIT;

   g_static_mutex_lock (&mutex_lock);

and before every return:
g_static_mutex_unlock (&mutex_lock);

That sould work, but that gives mit this trouble.

Thanks for every help.

Martin


-- 
If you've got an idea and need help,    ICQ: 72997139
or just need general encouragement,     MSN: kleinerdrache@gmx.at
write me a message. ;-)                 Yahoo-Messenger: walking2martin
                                         AIM: littlewizzard
/* src/ports-treeview.c */

#include <stdlib.h>

#include <gnome.h>
#include <gconf/gconf-client.h>
#include <ports/ports.h>

#include "globals.h"

#include "ports-treeview.h"

/* definition for helper functions in this file */
gint update_ports_treestore_run (gpointer data);



/* creates the global ports_treestore */
void create_global_ports_treestore (void)
{
  gports.portstreestore = gtk_tree_store_new (N_COLUMNS,  /* Total number of columns */
                                         G_TYPE_STRING,   /* Portname                */
                                         G_TYPE_STRING,   /* ID                      */
                                         G_TYPE_INT);     /* Color                   */
  gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(gports.portstreestore),
                                         PORTNAME_COLUMN,
                                         GTK_SORT_ASCENDING);
}


/* call this function to get the portstreeview rebuilt. */
void update_ports_treestore (void)
{
  GThread* thread;
  
  if (gports_search.running == TRUE)
    gports_search.stop = TRUE;
    
  if (!g_thread_supported ()) g_thread_init (NULL);
  thread = g_thread_create ((gpointer) update_ports_treestore_run,
                            NULL, TRUE, NULL);
}

/* this function get called with g_idle_add */
gint update_ports_treestore_run (gpointer data)
{
  GConfClient *client;
  gboolean show_categories, show_virtual;
  GtkProgressBar *progress;
  PortsSearchResult *result;
  gint id, catid, x, y, vcatids[10], nvcatids = 0;
  gchar *vcats, vcatid[4];
  PortsPortInfo *pinfo;
  GtkTreeIter iter, catiter[100], *thisiter[20];
  gint itercount, pulse = 0, pulse_count;
  gboolean catstored[100];
  static GStaticMutex mutex_lock = G_STATIC_MUTEX_INIT;
  
  g_static_mutex_lock (&mutex_lock);
  gports_search.running = TRUE;
  
  for(x=0; x < 100; x++) catstored[x] = FALSE;
  
  client = gconf_client_get_default ();
  show_categories = gconf_client_get_bool (client, 
                                 "/apps/gports/portstree/show_categories", NULL);
  show_virtual = gconf_client_get_bool (client,
                                 "/apps/gports/portstree/show_virtual", NULL);
  g_object_unref (client);
  progress = gnome_appbar_get_progress (GNOME_APPBAR (gports.appbar));
  
  gnome_appbar_set_status (GNOME_APPBAR (gports.appbar), _("Searching..."));
  while (gtk_events_pending()) gtk_main_iteration();
  
  result = ports_search_ports (gports.pdb, 
                               gports_search.searchstring, 
                               gports_search.searchfields,
                               gports_search.collections,
                               NULL, NULL);
  gnome_appbar_set_status (GNOME_APPBAR (gports.appbar), _("Search finished - loading..."));
  while (gtk_events_pending()) gtk_main_iteration();
  
  gtk_tree_store_clear(gports.portstreestore);
  while (gtk_events_pending()) gtk_main_iteration();
  /* adding item to the treeview */
  while ( (id = ports_search_get_next (result)) )
  {
    /* stop the function if a second search gets started */
    if(gports_search.stop == TRUE)
    {
      gports_search.stop = FALSE;
      gports_search.running = FALSE;
      g_static_mutex_unlock (&mutex_lock);
      return NULL;
    }
    
    pinfo = ports_get_port(gports.pdb, id, NULL);
    catid = atoi(ports_portinfo_get(pinfo, "cat"));
    itercount = 0;    
    /* add categories on show_categories */
    if (show_categories == TRUE)
    {
      if (catstored[catid] == FALSE)
      {
        gtk_tree_store_append (gports.portstreestore, &catiter[catid], NULL);
        gtk_tree_store_set (gports.portstreestore, &catiter[catid],
                    PORTNAME_COLUMN, ports_get_category_name(gports.pdb, catid, NULL),
                    ID_COLUMN, NULL,
                    COLOR_COLUMN, 0,
                    -1);
        catstored[catid] = TRUE;
        thisiter[itercount++] = &catiter[catid];
      }
      else
      {
        thisiter[itercount++] = &catiter[catid];
      }
      
      /* show virtual categories, only if show_categories is also true */
      if (show_virtual == TRUE)
      {
        vcats = ports_portinfo_get(pinfo, "vcats");
        y = 0;
        nvcatids = 0;
        for(x=0; x <= strlen(vcats); x++)
        {
          if(vcats[x] != ' ' && vcats[x] != 0) 
          {
            vcatid[y++] = vcats[x];
          }
          else
          {
            vcatid[y] = 0;
            vcatids[nvcatids] = atoi(vcatid);
            if (vcatids[nvcatids] != 0) nvcatids++; 
            y = 0;
          } 
        }
        
        for(x=0; x < nvcatids; x++)
        {
          catid = vcatids[x];
	        if (catstored[catid] == FALSE)
		      {
		        gtk_tree_store_append (gports.portstreestore, &catiter[catid], NULL);
		        gtk_tree_store_set (gports.portstreestore, &catiter[catid],
		                    PORTNAME_COLUMN, ports_get_category_name(gports.pdb, catid, NULL),
		                    ID_COLUMN, NULL,
		                    COLOR_COLUMN, 0,
		                    -1);
		        catstored[catid] = TRUE;
		        thisiter[itercount++] = &catiter[catid];
		      }
		      else
		      {
		        thisiter[itercount++] = &catiter[catid];
		      }
		    while (gtk_events_pending()) gtk_main_iteration();
	      }
      }
      pulse_count = 50;
    }
    else
    {
      itercount = 1;
      pulse_count = 1;
    }
    
    /* adding the port */
    for(x=0;x < itercount; x++)
    {
      if(show_categories == FALSE) {
        gtk_tree_store_append (gports.portstreestore, &iter, NULL);
      }
      else
      {
        gtk_tree_store_append (gports.portstreestore, &iter, thisiter[x]);
      }
      gtk_tree_store_set (gports.portstreestore, &iter,
                  PORTNAME_COLUMN, ports_portinfo_get(pinfo, "name"),
                  ID_COLUMN, ports_portinfo_get(pinfo, "ID"),
                  COLOR_COLUMN, 0,
                  -1);
      while (gtk_events_pending()) gtk_main_iteration();
    }
    
    if (pulse++ > pulse_count)
    {
      gtk_progress_bar_pulse (progress);
      pulse = 0;
    }
    while (gtk_events_pending()) gtk_main_iteration();
  }
  
  ports_search_free(result);
  gnome_appbar_clear_stack (GNOME_APPBAR(gports.appbar));
  gtk_progress_bar_set_fraction(progress, 0);
  
  gports_search.running = FALSE;
  g_static_mutex_unlock (&mutex_lock);
  return NULL;
}


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