I have to create a wrapper to the GD library to generate a thumbnail for
an image. This is the function I have written -
void _generate_thumbnail(char *sOriginal, char *sThumbnail, int w, int h)
{
gdImagePtr im;
FILE *fp;
unsigned int i;
char str[32];
int cbs;
im = gdImageCreateTrueColor(w, h);
if (im)
{
gdImageFilledRectangle(im, 2, 2, 80, 80, 0x50FF0000);
fp = fopen("c:\\myimage.png", "wb");
i = (unsigned int) &fp;
sprintf(str, "%u", i);
cbs = strlen(str);
WriteDebugLog("c:\\debug.log", str, cbs);
if (0 != fp)
{
gdImagePng(im, fp); // This is where it crashes
fclose(fp);
gdImageDestroy(im);
}
}
}
It always crashes on the line where I am writing the image to disk using
gdImagePng. I researched the error message ('Unhandled exception at
0x7c918fea in Apache.exe: 0xC0000005: Access violation writing location
0x00000010.') and learnt that it has something to do with a NULL pointer.
The gdImagePtr variable seems to be fine because the
gdImageFilledRectangle command succeeds. That leaves the file pointer.
But inspecting the value of the pointer reveals that it isn't NULL.
I'd appreciate someone shedding some light on what's going on here.
Regards,
Pranav
--
comp.lang.c.moderated - moderation address: cl...@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
>
> It always crashes on the line where I am writing the image to disk
> using gdImagePng. I researched the error message ('Unhandled
> exception at 0x7c918fea in Apache.exe: 0xC0000005: Access violation
> writing location 0x00000010.') and learnt that it has something to do
> with a NULL pointer.
>
> The gdImagePtr variable seems to be fine because the
> gdImageFilledRectangle command succeeds. That leaves the file
> pointer. But inspecting the value of the pointer reveals that it
> isn't NULL.
>
> I'd appreciate someone shedding some light on what's going on here.
>
The only general rule is that the cause of a "crash" is code executed
at OR BEFORE the point where the crash is detected.
Any of the functions you are calling could be the culprit. Most of
those functions are non-standard, so you need to read the documentation
for those functions.
While it's not related to your crash, writing the address of a FILE
pointer to a debug log (in any form) strikes me as a pointless exercise.
> I'm getting my head around the C language by working on a Windows
> extension for PHP. This problem relates to a non-Zend framework issue
> that I'm facing.
>
> I have to create a wrapper to the GD library to generate a thumbnail for
> an image. This is the function I have written -
there is a GD module already written for PHP also an image magick module.
alternatively you can probably find a port of netpbm and communicate
with that using system....
ob_start() (etc...) can be handy when php functions send their output
in the wrong direction.
Bye.
Jasen
> While it's not related to your crash, writing the address of a FILE
> pointer to a debug log (in any form) strikes me as a pointless exercise.
It proves if it's NULL or not ... desperate times and all that :)
Bye.
Jasen
> On 2008-07-09, Bob <nos...@does.not.exist> wrote:
>
> > While it's not related to your crash, writing the address of a FILE
> > pointer to a debug log (in any form) strikes me as a pointless
> > exercise.
>
> It proves if it's NULL or not ... desperate times and all that :)
>
Only to the paranoid. Following the declaration
FILE *fp;
&fp (which the code in the original post was printing out) is guaranteed
to be non-null.