Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NSObject allocWithZone:]: attempt to allocate object of class 'UITraitCollection' failed when setting image in CarPlay #2364

Open
markst opened this issue Feb 22, 2025 · 4 comments

Comments

@markst
Copy link

markst commented Feb 22, 2025

We're encountering a crash when using Kingfisher to set an image on a CPListItem in CarPlay. The crash throws an NSMallocException with the message:

[NSObject allocWithZone:]: attempt to allocate object of class 'UITraitCollection' failed

This occurs when calling setImage on the CPListItem.

Stack Trace:

Fatal Exception: NSMallocException
0  CoreFoundation                 __exceptionPreprocess
1  libobjc.A.dylib                objc_exception_throw
2  CoreFoundation                 +[NSObject(NSObject) doesNotRecognizeSelector:]
3  UIKitCore                      __66-[UITraitCollection _traitCollectionByModifyingTraitsCopyOnWrite:]_block_invoke_2
4  UIKitCore                      __96-[UITraitCollection _traitCollectionByPopulatingUnspecifiedTraitsWithValuesFromTraitCollection:]_block_invoke_2
5  UIKitCore                      _UITraitTokenSetEnumerate
6  UIKitCore                      __96-[UITraitCollection _traitCollectionByPopulatingUnspecifiedTraitsWithValuesFromTraitCollection:]_block_invoke
7  UIKitCore                      -[UITraitCollection _traitCollectionByModifyingTraitsCopyOnWrite:]
8  UIKitCore                      -[UIImageConfiguration _applyConfigurationValuesTo:]
9  UIKitCore                      -[UIImageConfiguration configurationByApplyingConfiguration:]
10 UIKitCore                      +[UIImageConfiguration _completeConfiguration:fromConfiguration:]
11 UIKitCore                      -[UIImageAsset _withLock_imageWithConfiguration:]
12 UIKitCore                      -[UIImageAsset imageWithConfiguration:]
13 UIKitCore                      -[UIImageAsset imageWithTraitCollection:]
14 CarPlay                        -[CPImageSet initWithImage:treatmentBlock:]
15 CarPlay                        -[CPListItem setImage:]
16 Listen                         closure #1 in KingfisherWrapper.setImage(with:imageAccessor:taskAccessor:placeholder:parsedOptions:progressBlock:completionHandler:) (HasImageComponent+Kingfisher.swift:454)

Steps to Reproduce:

  1. Use Kingfisher to load an image from a URL.
  2. Set the image on a CPListItem using Kingfisher's setImage method.
  3. The crash occurs during the setImage call.

Code Snippet:

let listItem = CPListItem(text: "Example", detailText: "Details")
listItem.kf.setImage(with: imageURL, placeholder: placeholderImage)

Environment:

  • Kingfisher Version: 8.1.3
  • iOS Versions Affected: All (88% on iOS 18)
  • CarPlay: Yes
  • Devices Affected: All
@markst
Copy link
Author

markst commented Feb 22, 2025

Happy to provide more details.

I'm going to try decoding the image on background thread:

item.kf.setImage(
    with: thumbnail,
    options: [.backgroundDecode]
)

@markst markst changed the title [NSObject allocWithZone:]: attempt to allocate object of class 'UITraitCollection' failed when setting image in CarPlay using Kingfisher [NSObject allocWithZone:]: attempt to allocate object of class 'UITraitCollection' failed when setting image in CarPlay Feb 22, 2025
@markst
Copy link
Author

markst commented Feb 22, 2025

On most occasions, the termination reasons are "exhausted real (wall clock) time allowance of 10.00 seconds" and "Failed to terminate gracefully after 5.0s," indicating the app is being terminated by the watchdog. I've added .backgroundDecode to offload decoding to a background thread to help prevent termination. We'll do further testing to evaluate the impact

@onevcat
Copy link
Owner

onevcat commented Feb 23, 2025

@markst I myself do not have a test environment for CarPlay now. May I know on which thread this crash happens? Is it thread 0 (the main thread)?

@markst
Copy link
Author

markst commented Feb 23, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants