3

在 Xcode 8 中激活地址清理程序时,我确实在以下代码行中遇到了问题:

UIImage *myImage = [UIImage imageNamed:imageName];

imageName是一个NSString,对应的图像存在于@1x,@2x,@3x。地址消毒剂问题:

=================================================================

==2484==错误:AddressSanitizer:尝试在不是 malloc()-ed 的地址上释放:线程 T0 中的 0x01d37310 #0 wrap_free 中的 0x1fff73 (/private/var/mobile/Containers/Bundle/Application/C92A762E-DAAF-46D9 -857B-151BAF97D0BB/Example.app/Frameworks/libclang_rt.asan_ios_dynamic.dylib+0x32f73) #1 0x2b50fab5 in (/System/Library/PrivateFrameworks/CoreUI.framework/CoreUI+0x2ab5) #2 0x2b50fbe5 in (/System/Library/PrivateFrameworks /CoreUI.framework/CoreUI+0x2be5) #3 0x2b5463e1 in (/System/Library/PrivateFrameworks/CoreUI.framework/CoreUI+0x393e1) #4 0x2b548307 in (/System/Library/PrivateFrameworks/CoreUI.framework/CoreUI+0x3b307) # 5 0x2b548233 在 (/System/Library/PrivateFrameworks/CoreUI.framework/CoreUI+0x3b233) #6 0x2b5606db 在 (/System/Library/PrivateFrameworks/CoreUI.framework/CoreUI+0x536db) #7 0x2b560233 in (/System/Library/PrivateFrameworks/CoreUI.framework/CoreUI+0x53233) #8 0x2924b611 in (/System/Library/Frameworks/UIKit.framework/UIKit+0x632611) #9 0x2924b375 in (/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 在(/System/Library/Frameworks/UIKit.framework/UIKit+0xf74b) #17 0x28c284bb in (/System/Library/Frameworks/UIKit.framework/UIKit+0xf4bb) #18 0x28c2e5e5 in (/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) #29 0x254d799f in CFRunLoopRunSpecific (/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation+0x1999f) #30 0x254d77b1 in CFRunLoopRunInMode (/System/Library/Frameworks/ CoreFoundation.framework/CoreFoundation+0x197b1) #31 0x28c8da55 in (/System/Library/Frameworks/UIKit.framework/UIKit+0x74a55) #32 0x28c88633 in UIApplicationMain (/System/Library/Frameworks/UIKit.framework/UIKit+0x6f633) # 34 0x34020aad 在 (/usr/lib/system/libdyld.dylib+0x1aad) 0x01d37310 位于 34 字节区域内的 0 字节 [0x01d37310,0x01d37332)

当我使用不存在的 imageName 时,地址清理程序对该行没有问题。

该问题似乎只影响 iOS 8,地址清理程序在 iOS 9 和 iOS 10(最新测试版)上没有问题。在 iOS 8 上,当我不将图像放入资产而是直接放入捆绑包时,它也可以工作。

4

1 回答 1

3

这似乎是 Xcode 8 Beta 6 (8S201h) 中的一个错误。将应用程序的部署目标设置为 iOS 8.3UIImage imageNamed:时,当引用的图像来自资产目录时,调用将崩溃。使用UIImage imageNamed:inBundle:compatibleWithTraitCollection:不会有什么不同。

解决方法:

  • 设置部署目标 < iOS 8.3。iOS 8.0/.1/.2 对我有用,8.3/.4 不断崩溃
  • 将图像直接放在应用程序包中,而不是资产目录

可以在GitHub 上找到此问题的示例项目

于 2016-08-31T11:45:58.127 回答