0

I need to create GdkPixBuf collection. I try to save pixbufs in GList - mw->disp_list:

GtkTreeIter iter;
int i = 0;

for (i; i < g_list_length(list) - 1; ++i)
{                       
  char* file = image_list_get_current_file_path( list );

  mw->p1 = gdk_pixbuf_new_from_file(file,NULL);
  mw->p1 = scale_pix(mw->p1,128);

  mw->disp_list = g_list_append (mw->disp_list, mw->p1);

  if (!mw->img_list->current->next )
      image_list_get_first(mw->img_list);
  else
      image_list_get_next(mw->img_list);
}

Where p1 - it's GtkPixBuf*.

But when i try to use mw->disp_list in another function i see that it is NULL. What's wrong?

Thank you.

0xAX
  • 20,957
  • 26
  • 117
  • 206
  • as first thing, I noticed as strange the for loop; you don't need the first part of the for, if you initialize the looping var outside it: `for(; i < ...` is ok, while `for(i; i <...` works too but i is evaluated without a reason; usually you write such a loop as `for(i=0; i < ...` and you can write simply `int i;` instead of `int i = 0;` – ShinTakezou Jul 02 '10 at 10:34
  • another note about the loop; `i < g_list_length(list)` is correct; unless with -1 you mean you want to loop one less more the length of the list (let us suppose you want use i as "index"; in this case, you would miss the last indexable element; without -1, you loop one time per element in list) – ShinTakezou Jul 02 '10 at 10:37

1 Answers1

1

At the moment I see just one problem, and it is about the loop that should be:

for (i = 0; i < g_list_length(list); ++i)

The problem could be the -1: if list contains 1 element, you do not loop at all, since 1-1 = 0 and 0 < 0 is false.

ShinTakezou
  • 9,432
  • 1
  • 29
  • 39