Problems with libpng

This is a discussion on Problems with libpng within the C Programming forums, part of the General Programming Boards category; I'm playing around with libpng, but I,m having problems allocating space. Heres what the manual says: After you have called ...

  1. #1
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218

    Problems with libpng

    I'm playing around with libpng, but I,m having problems allocating space. Heres what the manual says:
    After you have called png_read_png(), you can retrieve the image data with

    row_pointers = png_get_rows(png_ptr, info_ptr);

    where row_pointers is an array of pointers to the pixel data for each row:

    png_bytep row_pointers[height];
    Now, if I do this:
    Code:
    	png_bytep row_pointers[height+1]; //? is this right pointer type
    	row_pointers = png_get_rows(png_ptr, info_ptr); //Allcoate memory
    	png_read_image(png_ptr, row_pointers);			 //Read data
    I get errors on the second an third row about incompatible assignment/pointer types.

    If I do this:
    Code:
    	png_bytep *row_pointers[height+1];  //segfaults here
    	*row_pointers = png_get_rows(png_ptr, info_ptr); 
    	png_read_image(png_ptr,* row_pointers);
    It compiles but segfaults at the first line. Anyone know what I am meant to be oing with these pointer things here? Cheers.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,556
    Well since you can't return an array, it would be just a pointer.
    Say

    png_bytep *row_pointers = png_get_rows(png_ptr, info_ptr);

    IIRC, the examples in libpng show you how all this stuff works.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    png_bytep *row_pointers = png_get_rows(png_ptr, info_ptr);
    Cheer Salem, I tried this before but got segfaults. I'm doing it a slightly different way now working off an example. Been having internet connection problems today, so I was pretty much stuck with the manpage before. I'm still getting segfaults atm and I'm starting to get the impression that something else would be causing it. For example if I comment out this line:
    Code:
    unsigned long row_bytes, i;
    My code runs; otherwise it segfaults. wtf?

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,556
    Classic buffer overrun.
    Assign values to those variables, and you should see them being trashed (harmlessly), rather than something else (which is far from harmless).
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    Yep that was it. All the way at the beggining of my code, but it was easy to fix.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  2. String Manipulation problems -_-
    By Astra in forum C Programming
    Replies: 5
    Last Post: 12-13-2006, 04:48 PM
  3. Texture won't load (libpng with OpenGL)
    By OnionKnight in forum Game Programming
    Replies: 3
    Last Post: 10-04-2006, 10:28 PM
  4. Rendering problems (DirectX?)
    By OnionKnight in forum Tech Board
    Replies: 0
    Last Post: 08-17-2006, 12:17 PM
  5. DJGPP problems
    By stormswift in forum C Programming
    Replies: 2
    Last Post: 02-26-2002, 03:35 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21