View Single Post
Old Feb 1st, 2008, 2:25 PM   #1
dr.p
Programmer
 
dr.p's Avatar
 
Join Date: Feb 2006
Location: Ohio
Posts: 93
Rep Power: 3 dr.p is on a distinguished road
Read Access Violation

Big problem here.

I have a function WriteBmpPkgFile declared as:
DWORD WriteBmpPkgFile (const char *szFileName, LPBMPPKGFILE lpBmpPkg)

In that function, I have a file write call:
  fwrite(&(lpBmpPkg->dwCount), sizeof(BYTE), sizeof(DWORD), outfile);

A BMPPKGFILE is a struct that contains one or more bitmap files. The dwCount member is the number of bitmaps in the package.

When I get to that quoted fwrite line, and the program tries to write the dwCount member to outfile, I get a "Read Access Violation" exception and the program crashes.

BUT... this only happens when the bitmap is less than 4x4 pixels in size!

I allocate memory for the BMPPKGFILE struct when a bitmap is added, and I update the dwCount member, but I NEVER get any allocation errors or read/write access violations when adding a bitmap to a package.

Anyone have any idea why this would be happening? Or a suggestion on how to debug it better in MSVC++ Express 2005?

Here are the struct definitions, in case they help:
typedef struct tagBMPPKGFILE {
  DWORD          dwCount;          // How many images are in this file?
  BMPPKGENTRY   *pEntries;        // pEntries[0..(nCount-1)] = &BMPPKGENTRY
} BMPPKGFILE, *LPBMPPKGFILE;

typedef struct tagBMPPKGENTRY {
  DWORD        dwEntrySize;         // size of this entire entry, in bytes
  DWORD        dwNameSize;          // size of the szName field, in bytes (+\0)
  DWORD        dwFileSize;          // size of the bitmap data, in bytes
  char        *szName;              // pointer to the name
  BYTE        *pRawBmpFile;         // pointer to the raw bitmap file data
} BMPPKGENTRY, *LPBMPPKGENTRY;

Also, the BMPPKGFILE struct I'm using is created and initialized in this fashion:
  BMPPKGFILE bmppkg;
  ZeroMemory(&bmppkg, sizeof(BMPPKGFILE));
__________________
Neeley.org
dr.p is offline   Reply With Quote