Weird problem with UInt8 in iPhone (EXC_BAD_ACCESS)
I am developing an image processing application by converting image to bitmap. I am manipulating bits in bitmap to get the desired effect. First time i process an image it gives the correct result on the second try it gives EXC_BAD_ACCESS开发者_开发知识库
debugger is showing:
dataref outofscope
My code is
CGImageRef img=previewImageView.image.CGImage;
NSLog(@" Image : %@ ", previewImageView);
CFDataRef dataref=CopyImagePixels(img);
CFDataRef dataref1=CopyImagePixels(img);
//UInt8 *data=(UInt8 *)CFDataGetBytePtr(dataref);
//UInt8 *original=(UInt8 *)CFDataGetBytePtr(dataref1);
UInt8 *data=nil;
data=(UInt8 *)CFDataGetBytePtr(dataref);
UInt8 *original=nil;
original=(UInt8 *)CFDataGetBytePtr(dataref1);
//original=data;
int length=CFDataGetLength(dataref);
Please help.........
A major cause of EXEC_BAD_ACCESS is from trying to access release objects.
To find out how to troubleshoot this, read this document: DebuggingAutoReleasePool
Even if you don't think you are "releasing auto-released objects", this will apply to you.
This method works extremely well.
In summary, this explains how to use Cocoa's NSZombie debugging class and the command line "malloc_history" tool to find exactly what released object has been accessed in you code.
It is useful to set a breakpoint on objc_exception_throw. That way the debugger should break when you get the EXC_BAD_ACCESS.
Instructions can be found here http://www.cocoadev.com/index.pl?DebuggingTechniques
精彩评论