tags:

views:

1088

answers:

2

I copied this code from the libjpeg example and im passing it standard files;

FILE *soureFile;
if ((soureFile = fopen(sourceFilename, "rb")) == NULL)
{
    fprintf(stderr, "can't open %s\n", sourceFilename);
    exit(1);
}

jpeg_stdio_src(&jpegDecompress, soureFile);
jpeg_read_header(&jpegDecompress, true);

It results in a file pointer that contains no information and therefore breaks on the last line with access violations. Any ideas?

EDIT: On Tobias' advice the fopen does appear to open the file ok but the jpeg_read_header is in turn failing with the access violation still.

EDIT: After a little more digging
http://stackoverflow.com/questions/391917/jpeg-support-with-ijg-getting-access-violation

+2  A: 

Use strerror or perror to get exact reason:

FILE *soureFile;
if ((soureFile = fopen(sourceFilename, "rb")) == NULL)
{
    perror("fopen failed");
    exit(1);
}
Artyom
Didn't know about those thanks.However due to the valid pointer being return from fopen, this line will never be hit.
Adam Naylor
So in fact fopen() is working and the problem is with your jpeg code!
anon
+1  A: 

"select isn't broken".

If fopen returned a valid file pointer, and jpeg_read_header can't use it, someone between those two statements has done something bad to it.

The only one in between is the jpg_stdio_src call, which wouldn't fail if all it's preconditions are fulfilled.

Bottom line: see why jpg_stdio_src fails. My guess: it needs to be constructed using the jpeg_create_decompress macro.

xtofl