Still problems with gtk_list_store_append



Hi List

I didn't really resolve the problem the last time so i'm trying again in
hope that someone can help me. Its damn frustrating that it wont work.

To summarize the problem. I'm trying to add som data to a list store. It
works fine for the first rows but then suddenly it crashes with a
segfault. As far as I can tell it crashes when calling
gtk_list_store_append(). The data I'm trying to populate the list store
with comes from a GList of a struct that looks like this:

typedef struct {
  char * mid;
  char * title;
  char * director;
  char * year;
  char * genre;
  char * language;
  char * runtime;
  char * imdb;
  char * media;
  char * mediasource;
  char * mediaformat;
  char * discnumber;
  char * seen;
  char * borrowed;
} Movie;

My code for populating the list store is:

int repopulate_list(GtkWidget * widget, GtkListStore * model){
  GtkTreeIter iter;
  GList * movies = NULL;
  GList * movie_element;
  Movie * movie = NULL;
  FILE * fptr;
  int i = 0;

  printf("Clearing...\n");
  /* Clear list for repopulation */
  gtk_list_store_clear(model);
    
  printf("Open file for reading...\n");
  /* Populate list store */
  if(fopen(selected_filename, "r") != NULL){
    movies = listMovies(selected_filename);
  } else {
    fptr = fopen(selected_filename, "w");
    fprintf(fptr, "<?xml version=\"1.0\"?>\n");
    fprintf(fptr, "<movies></movies>\n");
  }
  
  printf("Get first...\n");
  movie_element = g_list_first(movies);
  while(movie_element != NULL){

    /* De reference list data */
    movie = (Movie*)movie_element->data;

    /* Set values on list... */
    printf("Appending...\n");
    gtk_list_store_append(model, &iter);
    printf("Set...\n");
    gtk_list_store_set(model, &iter, 0, movie->mid, 1, movie->title, 2,
movie->imdb, 3, movie->mediasource, 4, movie->mediaformat, 5,
movie->borrowed, -1);
    
    /* Go to next element in list */
    movie_element = g_list_next(movie_element);
  }

  return 1;
}

What is really strange is that when i start the program with an empty
list everything is fine, and I can even add lines for a while without
any troubles. But after it crashes with the segfault it wont event do
the first few lines. Output from the program after the first initial
segfault:

Populate...
Clearing...
Open file for reading...
Get first...
Append...
Segmentation fault

Cheers
Jesper




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