On Dec 14, 2009, at 10:27, gMail.com wrote:

> if I compile this code against "32-bits Universal", it works.
> If I compile this code against "64-bit Intel", it doesn't work.
> I get a bad access error just on memcpy. What do I miss? I use:
> 
>    Base SDK 10.6
>    i386 ppc ppc64 ppc7400 ppc970 x86_64
>    GCC 4.2 or 4.0
>    Target Mac OS X 10.6
>    Active Architecture x86_64
> 
> - (void)LoadImageData:(NSData*)imageData
>                       pointer:(void*)handle
>                               h:(GLuint)imageHeight
> {
>    NSBitmapImageRep    *bitmap = [[NSBitmapImageRep alloc]
>                                                    initWithData:imageData];
>    int                         bytesPRow = [bitmap bytesPerRow];
>    unsigned char        *theImageData = [bitmap bitmapData];
>    int                         rowNum;
> 
>    for(rowNum = 0; rowNum < imageHeight; rowNum++){
>        memcpy(handle + (rowNum * bytesPRow),
>                     theImageData + (rowNum * bytesPRow), bytesPRow);
>    }
> 
>    [bitmap release];
> }

This isn't a Cocoa question. You have a bug your code (most likely), and you 
need to debug it.

FWIW, I'd point out that you're exposing yourself to horrible problems with 
this code, since it lacks even the most fundamental sanity checks. What if the 
memory block pointed to by 'handle' is less than imageHeight*bytesPRow bytes? 
What if 'imageHeight' is greater than the number of rows in the image? You're 
not even going to check those things??


_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to