Iphone UIImageWriteToSavedPhotosAlbum带有malloc_错误
我有一个带按钮的NIB文件。单击此按钮时,将调用setWallpaper:选择器。除malloc抛出的错误外,一切都按预期工作(图像已保存)Iphone UIImageWriteToSavedPhotosAlbum带有malloc_错误,iphone,malloc,wallpaper,Iphone,Malloc,Wallpaper,我有一个带按钮的NIB文件。单击此按钮时,将调用setWallpaper:选择器。除malloc抛出的错误外,一切都按预期工作(图像已保存) malloc: *** error for object 0x184d000: pointer being freed was not allocated *** set a breakpoint in malloc_error_break to debug 我已经在malloc\u error\u break设置了一个断点,但是我不理解调试器中的任何内
malloc: *** error for object 0x184d000: pointer being freed was not allocated ***
set a breakpoint in malloc_error_break to debug
我已经在malloc\u error\u break设置了一个断点,但是我不理解调试器中的任何内容。我甚至找不到对象0x184d000。有人知道为什么会这样吗?在将UIImage发送到UIImageWriteToSavedPhotosAlbum之前,我也尝试过保留UIImage,但没有成功
我的代码如下:
- (IBAction)setWallpaper:(id)sender {
UIImage *image = [UIImage imageNamed:@"wallpaper_01.png"];
UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:NSLocalizedString(@"Galo!!!",@"Saved image message: title")
message:NSLocalizedString(@"Now, check your \"saved photos\" group at \"photos\" app in your iPhone and select the actions menu > set as wallpaper.",@"Saved image message")
delegate:nil
cancelButtonTitle:NSLocalizedString(@"OK",@"OK Button")
otherButtonTitles:nil];
[alertView show];
[alertView release];
}
UIImageWriteToSavedPhotosAlbum
以异步方式进行保存,这意味着您必须确保您的UIImage
在整个时间内保持不变。您正在向它传递一个自动释放的对象,因此它在尝试保存时会崩溃。更改setWallpaper:
以将retain
发送到UIImage
。然后您可以在回调中释放
或自动释放
它以避免泄漏。例如:
更改获取图像的行:
UIImage *image = [[UIImage imageNamed:@"wallpaper_01.png"] retain];
然后加上
[image release];
在回调中。好的,在克隆了几乎整个项目之后,我意识到问题来自OS3.0。改为OS3.1,一切正常。谢谢你的帮助,卡尔 我做到了。。。但仍然得到同样的错误。。。顺便说一下,我从malloc收到两条错误消息。两者完全相同。现在我创建了一个空项目,并复制了我的ViewController+NIB,它在那里工作得很好。。。我会检查它的任何框架或库添加到项目是造成一个错误。。。