Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Live app crash on UIImage imageNamed:

I'm having some weird issues with our app, it crashes when using some UIImage. I get the image with [UIImage imageNamed:@"imageName"] from the image asset. But on some device it returns nil which crash my app, but It should not be nil. I've already checked and its running on the main thread, there is enough memory left (although it was running low).

The image is PDF as single vector image in the image assets, this should create the correct sizes of the images.

Can any one give me any pointers on how to resolve this issue?

Thread : Crashed: com.apple.main-thread
0  CoreFoundation                 0x1844d7108 CFDataGetBytePtr + 36
1  Foundation                     0x18545a848 bytesInEncoding + 204
2  CoreFoundation                 0x1844e88d4 -[__NSCFString UTF8String] + 80
3  CoreUI                         0x18d6827c0 -[CUIStructuredThemeStore _canGetRenditionWithKey:isFPO:lookForSubstitutions:] + 780
4  CoreUI                         0x18d6a5614 -[CUICatalog _resolvedRenditionKeyFromThemeRef:withBaseKey:scaleFactor:deviceIdiom:deviceSubtype:sizeClassHorizontal:sizeClassVertical:memoryClass:graphicsClass:graphicsFallBackOrder:] + 1484
5  CoreUI                         0x18d6a4784 -[CUICatalog namedLookupWithName:scaleFactor:deviceIdiom:deviceSubtype:sizeClassHorizontal:sizeClassVertical:] + 148
6  UIKit                          0x18a3df338 __98-[_UIAssetManager imageNamed:scale:idiom:subtype:cachingOptions:sizeClassPair:attachCatalogImage:]_block_invoke + 424
7  UIKit                          0x18a3df0d8 -[_UIAssetManager imageNamed:scale:idiom:subtype:cachingOptions:sizeClassPair:attachCatalogImage:] + 212
8  UIKit                          0x18a4f1698 -[UIImageAsset imageWithTraitCollection:] + 404
9  UIKit                          0x18a3df7c0 -[_UIAssetManager imageNamed:withTrait:] + 276
10 UIKit                          0x189e7277c +[UIImage imageNamed:inBundle:compatibleWithTraitCollection:] + 220
11 UIKit                          0x189ccb47c +[UIImage imageNamed:] + 124
12 Speakap                        0x1000bef50 -[LoadingView commonInit] (LoadingView.m:74)
13 Speakap                        0x1000beabc -[LoadingView initWithFrame:] (LoadingView.m:28)
14 Speakap                        0x1001348dc -[BaseTableViewController viewDidLoad] (BaseTableViewController.m:32)
15 Speakap                        0x1001570d4 -[BaseMessageViewController viewDidLoad] (BaseMessageViewController.m:66)
16 Speakap                        0x10014aa34 -[MessageViewController viewDidLoad] (MessageViewController.m:37)
17 UIKit                          0x189b8c098 -[UIViewController loadViewIfRequired] + 996
18 UIKit                          0x189ba4350 -[UIViewController __viewWillAppear:] + 132
19 UIKit                          0x189d3dfb4 -[UINavigationController _startCustomTransition:] + 1052
20 UIKit                          0x189c4a190 -[UINavigationController _startDeferredTransitionIfNeeded:] + 688
21 UIKit                          0x189c49e6c -[UINavigationController __viewWillLayoutSubviews] + 60
22 UIKit                          0x189c49dd4 -[UILayoutContainerView layoutSubviews] + 208
23 UIKit                          0x189b877ac -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 644
24 QuartzCore                     0x189386b58 -[CALayer layoutSublayers] + 148
25 QuartzCore                     0x189381764 CA::Layer::layout_if_needed(CA::Transaction*) + 292
26 QuartzCore                     0x189381624 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 32
27 QuartzCore                     0x189380cc0 CA::Context::commit_transaction(CA::Transaction*) + 252
28 QuartzCore                     0x189380a08 CA::Transaction::commit() + 512
29 UIKit                          0x189b7d9d8 _afterCACommitHandler + 180
30 CoreFoundation                 0x1845afbd0 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
31 CoreFoundation                 0x1845ad974 __CFRunLoopDoObservers + 372
32 CoreFoundation                 0x1845adda4 __CFRunLoopRun + 928
33 CoreFoundation                 0x1844dcca0 CFRunLoopRunSpecific + 384
34 GraphicsServices               0x18f718088 GSEventRunModal + 180
35 UIKit                          0x189bf4ffc UIApplicationMain + 204
36 Speakap                        0x100162b24 main (main.m:14)
37 libdyld.dylib                  0x19990a8b8 start + 4
like image 329
rckoenes Avatar asked Dec 01 '15 14:12

rckoenes


2 Answers

I've experienced some "trouble" in memory management using [UIImage imageNamed:@""] within low memory context.

As the documentation says: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIImage_Class/index.html#//apple_ref/occ/clm/UIImage/imageNamed:

Discussion

This method looks in the system caches for an image object with the specified name and returns that object if it exists. If a matching image object is not already in the cache, this method locates and loads the image data from disk or asset catalog, and then returns the resulting object. In iOS 9 and later, this method is thread safe.

I don't know on which OS the crash happens, but it can be an idea.

Other point, does it still happens if your replace imageNamed: by imageWithContentOfFile: or initWithContentOfFile: ?

The memory management is different (no system cache): https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIImage_Class/index.html#//apple_ref/occ/instm/UIImage/initWithContentsOfFile:

Discussion

This method loads the image data into memory and marks it as purgeable. If the data is purged and needs to be reloaded, the image object loads that data again from the specified path.

like image 198
Alban Avatar answered Nov 18 '22 12:11

Alban


https://github.com/rickytan/RTImageAssets

install above plugin to xcode and go to file -> imageAssets ->Generate Missing assets.i will generate all missing images.

enter image description here

like image 1
Janak LN Avatar answered Nov 18 '22 12:11

Janak LN