Unhandled Exception... 
Author Message
 Unhandled Exception...

Greetings!  I have a runtime error that I'm hoping someone could help me
with.  The following is the error:

Unhandled exception in Myprog.exe (NTDLL.DLL): 0xC0000005: Access Violation

Upon debugging, it is appartently related to the following assebly code in
NTDLL.DLL

77F51BAA   inc         dword ptr [eax+10h]

In my code the problem occurs once the following function is called:

png_read_info(png, info);

During debugging, both png and info seemed to be allocated fine.

The following is my fucntion:

void *png_read(unsigned      *size_x,        // image width
      unsigned      *size_y,        // image height
      unsigned      *size_z,        // number of channels
      unsigned      *depth,         // datum depth in bytes
      const char    *filename,      // path
      bool          byteize         // convert to 8-bit depth when set
)
{

  void          *image;
  FILE          *fp;
  png_bytep     *row;
  png_byte      magic[8];
  png_structp   png;
  png_infop     info;
  unsigned      i;

  //
  // Wrapper for reading a PNG file.
  //

  ASSERT(!endian.is.little == !!endian.is.big, (""endian.is.little !=
!!endian.is.big));

  if (!(fp = fopen(filename, "rb")))
  {
    fprintf(stderr, "can't open '%s': %s\n", filename, strerror(errno));
    return NULL;
  }
  if (fread(magic, sizeof(magic), 1, fp) != 1) {
    fprintf(stderr, "can't read '%s': %s\n", filename, strerror(errno));
    fclose(fp);
    return NULL;
  }
  if (!png_check_sig(magic, sizeof(magic)))
  {
    MessageBox(NULL,"This is not a PNG file" ,NULL, MB_OK);
    fclose(fp);
    return NULL;
  }

  if (!(png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL,
NULL)))
  {
 MessageBox(NULL,"PNG read struct allocation failed" ,NULL, MB_OK);
    fclose(fp);
    return NULL;
  }

  if (!(info = png_create_info_struct(png)))
  {
    fprintf(stderr, "PNG info struct allocation failed\n");
    png_destroy_read_struct(&png, NULL, NULL);
    fclose(fp);
    return NULL;
  }

  if (setjmp(png_jmpbuf(png))) {
    fprintf(stderr, "setjmp() failed\n");
    png_destroy_read_struct(&png, &info, NULL);
    fclose(fp);
    return NULL;
  }

  png_init_io(png, fp);

  png_set_sig_bytes(png, sizeof(magic));

  png_read_info(png, info);  //   <----------------------- This point here

  png_set_packing(png);
  if (byteize)
  {
    png_set_strip_16(png);
  }
  else if (endian.is.little)
    png_set_swap(png);

  png_read_update_info(png, info);

  ASSERT(info->bit_depth % CHAR_BIT == 0, ("info->bit_depth % CHAR_BIT !=
0"));
  *size_x = (unsigned)info->width;
  *size_y = (unsigned)info->height;
  *size_z = (unsigned)info->channels;
  if (depth)
    *depth = (unsigned)info->bit_depth / CHAR_BIT;

  if (!(row = (unsigned char **)malloc(*size_y * sizeof(png_bytep))) ||
      !(image = row[*size_y - 1] = (unsigned char *)malloc(*size_y *
info->rowbytes))) {
    fprintf(stderr, "malloc() for PNG data failed\n");
    png_destroy_read_struct(&png, &info, NULL);
    fclose(fp);
    return NULL;
  }
  for (i = *size_y - 1; i; i--)
    row[i - 1] = row[i] + info->rowbytes;

  png_read_image(png, row);
  png_read_end(png, NULL);
  png_destroy_read_struct(&png, &info, NULL);

  free(row);
  fclose(fp);

  return image;

Quote:
}

Thanks, Jay


Wed, 29 Jun 2005 11:16:02 GMT  
 Unhandled Exception...
Where is png_read_info defined???? What does it do internally???

- Onkar


Quote:
> Greetings!  I have a runtime error that I'm hoping someone could help me
> with.  The following is the error:

> Unhandled exception in Myprog.exe (NTDLL.DLL): 0xC0000005: Access
Violation

> Upon debugging, it is appartently related to the following assebly code in
> NTDLL.DLL

> 77F51BAA   inc         dword ptr [eax+10h]

> In my code the problem occurs once the following function is called:

> png_read_info(png, info);

> During debugging, both png and info seemed to be allocated fine.

> The following is my fucntion:

> void *png_read(unsigned      *size_x,        // image width
>       unsigned      *size_y,        // image height
>       unsigned      *size_z,        // number of channels
>       unsigned      *depth,         // datum depth in bytes
>       const char    *filename,      // path
>       bool          byteize         // convert to 8-bit depth when set
> )
> {

>   void          *image;
>   FILE          *fp;
>   png_bytep     *row;
>   png_byte      magic[8];
>   png_structp   png;
>   png_infop     info;
>   unsigned      i;

>   //
>   // Wrapper for reading a PNG file.
>   //

>   ASSERT(!endian.is.little == !!endian.is.big, (""endian.is.little !=
> !!endian.is.big));

>   if (!(fp = fopen(filename, "rb")))
>   {
>     fprintf(stderr, "can't open '%s': %s\n", filename, strerror(errno));
>     return NULL;
>   }
>   if (fread(magic, sizeof(magic), 1, fp) != 1) {
>     fprintf(stderr, "can't read '%s': %s\n", filename, strerror(errno));
>     fclose(fp);
>     return NULL;
>   }
>   if (!png_check_sig(magic, sizeof(magic)))
>   {
>     MessageBox(NULL,"This is not a PNG file" ,NULL, MB_OK);
>     fclose(fp);
>     return NULL;
>   }

>   if (!(png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL,
> NULL)))
>   {
>  MessageBox(NULL,"PNG read struct allocation failed" ,NULL, MB_OK);
>     fclose(fp);
>     return NULL;
>   }

>   if (!(info = png_create_info_struct(png)))
>   {
>     fprintf(stderr, "PNG info struct allocation failed\n");
>     png_destroy_read_struct(&png, NULL, NULL);
>     fclose(fp);
>     return NULL;
>   }

>   if (setjmp(png_jmpbuf(png))) {
>     fprintf(stderr, "setjmp() failed\n");
>     png_destroy_read_struct(&png, &info, NULL);
>     fclose(fp);
>     return NULL;
>   }

>   png_init_io(png, fp);

>   png_set_sig_bytes(png, sizeof(magic));

>   png_read_info(png, info);  //   <----------------------- This point here

>   png_set_packing(png);
>   if (byteize)
>   {
>     png_set_strip_16(png);
>   }
>   else if (endian.is.little)
>     png_set_swap(png);

>   png_read_update_info(png, info);

>   ASSERT(info->bit_depth % CHAR_BIT == 0, ("info->bit_depth % CHAR_BIT !=
> 0"));
>   *size_x = (unsigned)info->width;
>   *size_y = (unsigned)info->height;
>   *size_z = (unsigned)info->channels;
>   if (depth)
>     *depth = (unsigned)info->bit_depth / CHAR_BIT;

>   if (!(row = (unsigned char **)malloc(*size_y * sizeof(png_bytep))) ||
>       !(image = row[*size_y - 1] = (unsigned char *)malloc(*size_y *
> info->rowbytes))) {
>     fprintf(stderr, "malloc() for PNG data failed\n");
>     png_destroy_read_struct(&png, &info, NULL);
>     fclose(fp);
>     return NULL;
>   }
>   for (i = *size_y - 1; i; i--)
>     row[i - 1] = row[i] + info->rowbytes;

>   png_read_image(png, row);
>   png_read_end(png, NULL);
>   png_destroy_read_struct(&png, &info, NULL);

>   free(row);
>   fclose(fp);

>   return image;

> }

> Thanks, Jay



Sat, 02 Jul 2005 02:54:30 GMT  
 Unhandled Exception...

Hi Jay,
You didn't provide code for the "png_read_info" function so its hard to say
where is the problem. Also I would suggest looking on call stack when the
exception occurs and this will help you to determine the problematic line
instead of problematic function.

Regards,
  Kobi Ben Tzvi

Quote:
> Greetings!  I have a runtime error that I'm hoping someone could help me
> with.  The following is the error:

> Unhandled exception in Myprog.exe (NTDLL.DLL): 0xC0000005: Access
Violation

> Upon debugging, it is appartently related to the following assebly code in
> NTDLL.DLL

> 77F51BAA   inc         dword ptr [eax+10h]

> In my code the problem occurs once the following function is called:

> png_read_info(png, info);

> During debugging, both png and info seemed to be allocated fine.

> The following is my fucntion:

> void *png_read(unsigned      *size_x,        // image width
>       unsigned      *size_y,        // image height
>       unsigned      *size_z,        // number of channels
>       unsigned      *depth,         // datum depth in bytes
>       const char    *filename,      // path
>       bool          byteize         // convert to 8-bit depth when set
> )
> {

>   void          *image;
>   FILE          *fp;
>   png_bytep     *row;
>   png_byte      magic[8];
>   png_structp   png;
>   png_infop     info;
>   unsigned      i;

>   //
>   // Wrapper for reading a PNG file.
>   //

>   ASSERT(!endian.is.little == !!endian.is.big, (""endian.is.little !=
> !!endian.is.big));

>   if (!(fp = fopen(filename, "rb")))
>   {
>     fprintf(stderr, "can't open '%s': %s\n", filename, strerror(errno));
>     return NULL;
>   }
>   if (fread(magic, sizeof(magic), 1, fp) != 1) {
>     fprintf(stderr, "can't read '%s': %s\n", filename, strerror(errno));
>     fclose(fp);
>     return NULL;
>   }
>   if (!png_check_sig(magic, sizeof(magic)))
>   {
>     MessageBox(NULL,"This is not a PNG file" ,NULL, MB_OK);
>     fclose(fp);
>     return NULL;
>   }

>   if (!(png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL,
> NULL)))
>   {
>  MessageBox(NULL,"PNG read struct allocation failed" ,NULL, MB_OK);
>     fclose(fp);
>     return NULL;
>   }

>   if (!(info = png_create_info_struct(png)))
>   {
>     fprintf(stderr, "PNG info struct allocation failed\n");
>     png_destroy_read_struct(&png, NULL, NULL);
>     fclose(fp);
>     return NULL;
>   }

>   if (setjmp(png_jmpbuf(png))) {
>     fprintf(stderr, "setjmp() failed\n");
>     png_destroy_read_struct(&png, &info, NULL);
>     fclose(fp);
>     return NULL;
>   }

>   png_init_io(png, fp);

>   png_set_sig_bytes(png, sizeof(magic));

>   png_read_info(png, info);  //   <----------------------- This point here

>   png_set_packing(png);
>   if (byteize)
>   {
>     png_set_strip_16(png);
>   }
>   else if (endian.is.little)
>     png_set_swap(png);

>   png_read_update_info(png, info);

>   ASSERT(info->bit_depth % CHAR_BIT == 0, ("info->bit_depth % CHAR_BIT !=
> 0"));
>   *size_x = (unsigned)info->width;
>   *size_y = (unsigned)info->height;
>   *size_z = (unsigned)info->channels;
>   if (depth)
>     *depth = (unsigned)info->bit_depth / CHAR_BIT;

>   if (!(row = (unsigned char **)malloc(*size_y * sizeof(png_bytep))) ||
>       !(image = row[*size_y - 1] = (unsigned char *)malloc(*size_y *
> info->rowbytes))) {
>     fprintf(stderr, "malloc() for PNG data failed\n");
>     png_destroy_read_struct(&png, &info, NULL);
>     fclose(fp);
>     return NULL;
>   }
>   for (i = *size_y - 1; i; i--)
>     row[i - 1] = row[i] + info->rowbytes;

>   png_read_image(png, row);
>   png_read_end(png, NULL);
>   png_destroy_read_struct(&png, &info, NULL);

>   free(row);
>   fclose(fp);

>   return image;

> }

> Thanks, Jay



Thu, 30 Jun 2005 22:03:06 GMT  
 Unhandled Exception...

Hi,

Try to debug your application in VC. When this exception occurs, check the
source stack. It can help you position the exact code position instead of
the function.

This posting is provided "AS IS" with no warranties, and confers no rights.

George Zheng [MSFT]



Sat, 02 Jul 2005 17:02:47 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Need help using __hook for unhandled exceptions.

2. Error: Unhandled Exception for Windows Form - HELP!

3. Unhandled exception System.TypeLoadException

4. Unhandled Exception:User Breakpoint Message

5. Unhandled Exception in RegAsm.exe

6. delegate to trap unhandled exception

7. UNHANDLED EXCEPTION !!!!

8. Unhandled exception in xxx.exe: 0xC00000005

9. Unhandled exception

10. UNHANDLED EXCEPTION !

11. unhandled exception SOS

12. Unhandled exception

 

 
Powered by phpBB® Forum Software