Jump to content
  • Advertisement
Sign in to follow this  
vallentin

Problem with libpng and Visual C++ Express Edition

This topic is 3678 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I tried to create a small program in C and link it against libpng
#include <stdio.h>
#include <malloc.h>
#include "png.h"
#include "cartographer.h"

void savePng( FILE * fp, unsigned __int16 raster_index)
{
    unsigned __int8 trans[]={_transparent_color};
    png_infop info_ptr;
    png_structp png_ptr;
    png_ptr = png_create_write_struct
    (PNG_LIBPNG_VER_STRING, 
    NULL, NULL, NULL);
    if (!png_ptr)
       return ;
    info_ptr = png_create_info_struct(png_ptr);
    if (!info_ptr)
    {
       png_destroy_write_struct(&png_ptr,
         (png_infopp)NULL);
       return;
    }
    if (setjmp(png_jmpbuf(png_ptr))) 
    {
        png_destroy_write_struct(&png_ptr, &info_ptr);
        return;
    }
    png_init_io(png_ptr, fp);

    /* set the zlib compression level */
    png_set_compression_level(png_ptr,
        Z_NO_COMPRESSION);

    /*set information chunk*/
    png_set_IHDR(png_ptr, info_ptr, _width, _height,
       _bit_depth, PNG_COLOR_TYPE_PALETTE, PNG_INTERLACE_NONE,
       PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);

    png_set_packing(png_ptr);

    png_set_PLTE(png_ptr, info_ptr, _palette,
       _palette_count);

    png_set_tRNS(png_ptr, info_ptr, trans, 1,
       NULL);

    png_write_info(png_ptr, info_ptr);//<------it stops here

    png_set_flush(png_ptr, _height);
	
    png_write_image(png_ptr, _rasters+raster_index);

    png_write_end(png_ptr, info_ptr);

    png_destroy_write_struct(&png_ptr, &info_ptr);
}



However it gives me an error in form of: Unhandled exception at 0x776bb15f in child_server.exe: 0xC0000005: Access violation writing location 0x00000014. The project is called child_server.exe [Edited by - vallentin on May 29, 2008 11:36:24 AM]

Share this post


Link to post
Share on other sites
Advertisement
Are you sure fp isn't NULL?

The program tries to write to memory adress 0x00000014. That is NULL plus a small offset of 0x14 = 20 bytes, that suggests you have an unchecked NULL pointer in there. It can't be info_ptr or png_ptr, because you check them both. This only leaves fp as I see no other pointers in there.

Share this post


Link to post
Share on other sites
you may be right about the NULL thing, but fp is actually 1700140104(0x65561448)

[Edited by - vallentin on May 30, 2008 11:35:12 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by vallentin
you may be right about the NULL thingie, but fp is actually 1700140104(0x65561448)
I find that hard to believe. That's an extremely high address, and it certainly doesn't look like a file pointer, which is stored as a global internally. Or is this Vista?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!