UIImage imagenamed crash

Hello there, I am having truble while using [UIImage imageNamed:] method

It appeares that crash occured when launching app from killed state and getting an resource image.

All my images are stored in bundle and no issue with background thread.

Following is crash log


Thread : Crashed: com.apple.main-thread

0 libsystem_kernel.dylib 0x180e9c11c __pthread_kill + 8

1 libsystem_pthread.dylib 0x180f68ef8 pthread_kill + 112

2 libsystem_c.dylib 0x180e0ddac abort + 140

3 libsystem_malloc.dylib 0x180ed0d24 free_list_checksum_botch + 438

4 libsystem_malloc.dylib 0x180ed0d48 free_list_checksum_botch + 36

5 libsystem_malloc.dylib 0x180ec6e60 tiny_malloc_from_free_list + 1180

6 libsystem_malloc.dylib 0x180ec55ac szone_malloc_should_clear + 268

7 libsystem_malloc.dylib 0x180ec5458 malloc_zone_malloc + 116

8 CoreFoundation 0x181334e04 __CFBasicHashRehash + 172

9 CoreFoundation 0x1813366e4 __CFBasicHashAddValue + 100

10 CoreFoundation 0x1811dc054 CFDictionarySetValue + 248

11 ImageIO 0x182d808a8 CGImagePlusSetImageBlockProc + 432

12 ImageIO 0x182d7fe00 CGImagePluginSetImageBlockProc + 144

13 ImageIO 0x182d7caa8 initImagePng + 6736

14 ImageIO 0x182d7a80c makeImagePlus + 1252

15 ImageIO 0x182d79db4 CGImageSourceCreateImageAtIndex + 184

16 UIKit 0x1864b50f4 ImageRefAtPath + 332

17 UIKit 0x1864b4f4c GetImageAtPath + 36

18 UIKit 0x186de47d4 -[_UIPathLazyImageAsset imageWithTraitCollection:] + 252

19 UIKit 0x186739714 +[UIImage imageNamed:inBundle:compatibleWithTraitCollection:] + 380

20 UIKit 0x18658cc8c +[UIImage imageNamed:] + 124

21 OfficeChat 0x100591ab4 -[TestScreen initWithFrame:] (HomeScreenView.mm:148)

22 OfficeChat 0x10058df54 -[TestController init] (HomeScreenController.mm:45)

26 OfficeChat 0x100082054 -[PulseAppDelegate StartUI] (PulseAppDelegate.mm:705)

27 OfficeChat 0x100080dd8 -[PulseAppDelegate application:didFinishLaunchingWithOptions:] (PulseAppDelegate.mm:235)

28 UIKit 0x1864c28a8 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 400

29 UIKit 0x1866f2094 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2904

30 UIKit 0x1866f6500 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1684

31 UIKit 0x1866f3674 -[UIApplication workspaceDidEndTransaction:] + 168

32 FrontBoardServices 0x182ca37ac __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 36

33 FrontBoardServices 0x182ca3618 -[FBSSerialQueue _performNext] + 168

34 FrontBoardServices 0x182ca39c8 -[FBSSerialQueue _performNextFromRunLoopSource] + 56

35 CoreFoundation 0x1812b9124 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24

36 CoreFoundation 0x1812b8bb8 __CFRunLoopDoSources0 + 540

37 CoreFoundation 0x1812b68b8 __CFRunLoopRun + 724

38 CoreFoundation 0x1811e0d10 CFRunLoopRunSpecific + 384

39 UIKit 0x1864bb834 -[UIApplication _run] + 460

40 UIKit 0x1864b5f70 UIApplicationMain + 204

41 OfficeChat 0x10008041c main (main.mm:13)

42 libdyld.dylib 0x180d7e8b8 start + 4

Replies

By "launching app from killed state," do you mean a cold launch, like the first one after the Simulator is opened?

I mean by launchinfg app when its not running in background, after launch. But not in simulator on device, iPhone 6. This crash is not always reproducible, is it has to do something with the 3x images because i hve 2x image but not 3x in my bundle.

Did you look at whatever image is being loaded in the problem code? You might also want to crack open a compiled build of your app to make sure that all of the resources made it into the bundle. (Unless you use asset catalogs, in which case you can't see the compiled resources.)


At this point, I'm pretty sure it's a bug within iOS, so you should probably go ahead and file a bug report (here's the link if you need it: bugreport.apple.com). So all we're doing now is attempting to isolate the problem so that it can be reproduced and eventually figure out a workaround. Be sure to keep your bug report updated with new information as you discover it.

I am experiencing a similar issue on an iPad app. The crash is sporadic but I've isolated it to [UIImage imageNamed]. I had set an malloc_error_break breakpoint and it appears the cached UIImage that's being loaded has been released. When I change from imageNamed to initWithContentsOfFile, the crash no longer occurs. It appears to be a bug with the caching/purging system of imageNamed.

Have you solved it? I have met the same problem.