Iphone 找不到exc_bad_访问的行,存在异常断点并设置NSZombies类
该代码应该将从picker视图中选择的图像的数据块上传到网站,但每次我尝试上传一个特定的数据块时,它都会给我一个EXC_BAD_访问权限。以下是将图像数据拆分为数据块的代码Iphone 找不到exc_bad_访问的行,存在异常断点并设置NSZombies类,iphone,ios,objective-c,uiimageview,Iphone,Ios,Objective C,Uiimageview,该代码应该将从picker视图中选择的图像的数据块上传到网站,但每次我尝试上传一个特定的数据块时,它都会给我一个EXC_BAD_访问权限。以下是将图像数据拆分为数据块的代码 PrimaryImageController.h @interface PrimaryImageViewController { __weak IBOutlet UIImageView *imgView; } @property (nonatomic,strong) NSMutableArray *chunk
PrimaryImageController.h
@interface PrimaryImageViewController
{
__weak IBOutlet UIImageView *imgView;
}
@property (nonatomic,strong) NSMutableArray *chunkArray;
PrimaryImageController.m
@synthesize imgView,chunkArray;
- (void)viewDidLoad
{
chunkArray=[[NSMutableArray alloc]init];
}
-(void)updateImage
{
UIImage *img = imgView.image;
NSData *dataObj=UIImageJPEGRepresentation(img, 1.0);
NSUInteger length = [dataObj length];
NSUInteger chunkSize = 3072*10;
NSUInteger offset = 0;
int numberOfChunks=0;
do
{
NSUInteger thisChunkSize = length - offset > chunkSize ? chunkSize : length - offset;
NSData* chunk = [NSData dataWithBytesNoCopy:(char *)[dataObj bytes] + offset
length:thisChunkSize
freeWhenDone:NO];
offset += thisChunkSize;
[chunkArray insertObject:chunk atIndex:numberOfChunks];
numberOfChunks++;
}
while (offset < length);
for (int i=0; i<[chunkArray count]; i++)
{
[uploadPrimary uploadImage:[chunkArray objectAtIndex:i] uuid:uniqueIdString numberOfChunks:[chunkArray count] currentChunk:i];
}
}
PrimaryImageController.h
@接口PrimaryImageViewController
{
__弱IBUIImageView*imgView;
}
@属性(非原子,强)NSMutableArray*chunkArray;
PrimaryImageController.m
@综合imgView、chunkArray;
-(无效)viewDidLoad
{
chunkArray=[[NSMutableArray alloc]init];
}
-(void)updateImage
{
UIImage*img=imgView.image;
NSData*dataObj=UIImageJPEG表示法(img,1.0);
NSU整数长度=[dataObj长度];
NSU整数chunkSize=3072*10;
整数偏移=0;
int numberOfChunks=0;
做
{
NSUInteger thisChunkSize=长度-偏移>chunkSize?chunkSize:长度-偏移;
NSData*chunk=[NSData dataWithBytesNoCopy:(字符*)[dataObj字节]+偏移量
长度:thisChunkSize
freeWhenDone:否];
偏移量+=此块大小;
[chunkArray-insertObject:chunk-atIndex:numberOfChunks];
numberOfChunks++;
}
而(偏移量<长度);
for(int i=0;iexc_bad_access
表示硬崩溃,不多也不少。虽然过度释放对象通常会导致这种情况,但可能发生这种崩溃的原因还有很多。同样,硬崩溃在NSException
意义上不是异常;设置异常断点也无济于事
如果你有一个崩溃,你应该有一个回溯。发布崩溃的回溯
如果启用了ARC,这看起来像是内部指针问题。您正在创建一组对dataObj
中包含的数据的引用,但不再引用dataObj
尝试将[dataObj self];
添加到()的循环之后
但是,由于您将块存储在一个作为实例变量的数组中,因此dataObj
的寿命应与该数组的寿命相耦合。即,要么将数组移动到updateImage
方法中,要么将iVar声明为强引用dataObj在哪里定义了chunkArray
@RichardBrown在控制器的viewDidLoad中定义了它。您可以添加定义和分配吗?@RichardBrown添加了imgView的定义和分配以及崩溃时控制台窗口中收到的任何消息的ChunkArrayId?