在Xcode 8中激活地址清理程序时,我在以下代码行中遇到问题:
UIImage *myImage = [UIImage imageNamed:imageName];
imageName
是一个NSString,相应的图像存在于@ 1x,@ 2x中,
@ 3倍。地址消毒剂问题:
=================================================================
== 2484 ==错误:AddressSanitizer:在线程T0中尝试释放不是malloc() - ed:0x01d37310的地址 wrap_free中的#0 0x1fff73(/private/var/mobile/Containers/Bundle/Application/C92A762E-DAAF-46D9-857B-151BAF97D0BB/Example.app/Frameworks/libclang_rt.asan_ios_dynamic.dylib+0x32f73) #1 0x2b50fab5(/System/Library/PrivateFrameworks/CoreUI.framework/CoreUI+0x2ab5) #2 0x2b50fbe5(/System/Library/PrivateFrameworks/CoreUI.framework/CoreUI+0x2be5) #3 0x2b5463e1 in(/System/Library/PrivateFrameworks/CoreUI.framework/CoreUI+0x393e1) #4 0x2b548307(/System/Library/PrivateFrameworks/CoreUI.framework/CoreUI+0x3b307) #5 0x2b548233 in(/System/Library/PrivateFrameworks/CoreUI.framework/CoreUI+0x3b233) #6 0x2b5606db in(/System/Library/PrivateFrameworks/CoreUI.framework/CoreUI+0x536db) #7 0x2b560233(/System/Library/PrivateFrameworks/CoreUI.framework/CoreUI+0x53233) #8 0x2924b611(/System/Library/Frameworks/UIKit.framework/UIKit+0x632611) #9 0x2924b375(/System/Library/Frameworks/UIKit.framework/UIKit+0x632375) #10 0x2924baf3 in(/System/Library/Frameworks/UIKit.framework/UIKit+0x632af3) #11 0x28eaf8bd in(/System/Library/Frameworks/UIKit.framework/UIKit+0x2968bd) #12 0x28d46e45 in(/System/Library/Frameworks/UIKit.framework/UIKit+0x12de45) #13 0x76c4d1 in - [MyClass myMethod](/private/var/mobile/Containers/Bundle/Application/C92A762E-DAAF-46D9-857B-151BAF97D0BB/Example.app/Frameworks/XY.framework/XY+0x2e4d1) #16 0x28c2874b in(/System/Library/Frameworks/UIKit.framework/UIKit+0xf74b) #17 0x28c284bb in(/System/Library/Frameworks/UIKit.framework/UIKit+0xf4bb) #18 0x28c2e5e5(/System/Library/Frameworks/UIKit.framework/UIKit+0x155e5) #19 0x28c2bf5d in(/System/Library/Frameworks/UIKit.framework/UIKit+0x12f5d) #20 0x28c9707f in(/System/Library/Frameworks/UIKit.framework/UIKit+0x7e07f) #21 0x28e8a505 in(/System/Library/Frameworks/UIKit.framework/UIKit+0x271505) #22 0x28e8cacd in(/System/Library/Frameworks/UIKit.framework/UIKit+0x273acd) #23 0x28e977a7 in(/System/Library/Frameworks/UIKit.framework/UIKit+0x27e7a7) #24 0x28e8b285 in(/System/Library/Frameworks/UIKit.framework/UIKit+0x272285) #25 0x2c09aebf in(/System/Library/PrivateFrameworks/FrontBoardServices.framework/FrontBoardServices+0x15ebf) #26 0x2558e253 in(/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation+0xd0253) #27 0x2558d517 in(/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation+0xcf517) #28 0x2558c071 in(/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation+0xce071) CFRunLoopRunSpecific中的#29 0x254d799f(/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation+0x1999f) CFRunLoopRunInMode中的#30 0x254d77b1(/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation+0x197b1) #31 0x28c8da55 in(/System/Library/Frameworks/UIKit.framework/UIKit+0x74a55) UIApplicationMain中的#32 0x28c88633(/System/Library/Frameworks/UIKit.framework/UIKit+0x6f633) #34 0x34020aad in(/usr/lib/system/libdyld.dylib+0x1aad) 0x01d37310位于34字节区域内的0字节[0x01d37310,0x01d37332]
当我使用不存在的imageName时,地址清理程序对该行没有任何问题。
问题似乎只影响iOS 8,地址清理程序在iOS 9和iOS 10(最新测试版)上没有问题。在iOS 8上,当我不将图像放入资源但直接放入包中时,它也可以工作。
答案 0 :(得分:3)
这似乎是Xcode 8 Beta 6(8S201h)中的一个错误。
将应用程序的部署目标设置为iOS 8.3时,当引用的图像来自资产目录时,调用UIImage imageNamed:
将会崩溃。使用UIImage imageNamed:inBundle:compatibleWithTraitCollection:
无济于事。
解决方法:
可以在GitHub
上找到此问题的示例项目