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

Crash +[SDImageCoderHelper CGImageCreateDecoded:orientation:] #3641

Open
3 tasks done
tac-han opened this issue Nov 16, 2023 · 5 comments
Open
3 tasks done

Crash +[SDImageCoderHelper CGImageCreateDecoded:orientation:] #3641

tac-han opened this issue Nov 16, 2023 · 5 comments
Labels

Comments

@tac-han
Copy link

tac-han commented Nov 16, 2023

New Issue Checklist

Issue Info

Info Value
Platform Name ios
Platform Version 16
SDWebImage Version 5.18.4
Integration Method SwiftPackage
Xcode Version Xcode 15
Repro rate sometimes
Repro with our demo prj e.g. does it happen with our demo project?
Demo project link e.g. link to a demo project that highlights the issue

Issue Description and Steps

Please fill in the detailed description of the issue (full output of any stack trace, compiler error, ...) and the steps to reproduce the issue.

image
Crashed: com.hackemist.SDWebImageDownloaderOperation.coderQueue (QOS: UNSPECIFIED)
0  libsystem_platform.dylib       0xe14 _platform_memmove + 84
1  ImageIO                        0x1ceb58 <redacted> + 88
2  ImageIO                        0x1df98c <redacted> + 56
3  ImageIO                        0x1df920 <redacted> + 84
4  ImageIO                        0x1df100 <redacted> + 868
5  ImageIO                        0x1966c <redacted> + 228
6  ImageIO                        0x153d0 <redacted> + 740
7  ImageIO                        0x1cf30 <redacted> + 840
8  CoreGraphics                   0x41fbc imageProvider_retain_data + 88
9  CoreGraphics                   0x5f50c CGDataProviderRetainData + 84
10 CoreGraphics                   0x7bb74 provider_for_destination_retain_data + 24
11 CoreGraphics                   0x5f50c CGDataProviderRetainData + 84
12 CoreGraphics                   0x3eeb4 CGAccessSessionCreate + 104
13 CoreGraphics                   0xc18c img_data_lock + 2404
14 CoreGraphics                   0x509c8 CGSImageDataLock + 1324
15 CoreGraphics                   0x24100 ripc_AcquireRIPImageData + 708
16 CoreGraphics                   0x4120c ripc_DrawImage + 820
17 CoreGraphics                   0x181b0 CGContextDrawImageWithOptions + 1112
18 App                        0x2d2a70 +[SDImageCoderHelper CGImageCreateDecoded:orientation:] + 4333939312
19 App                        0x2d5b04 +[SDImageIOAnimatedCoder createFrameAtIndex:source:scale:preserveAspectRatio:thumbnailSize:lazyDecode:animatedImage:] + 4333951748
20 App                        0x2d7728 -[SDImageIOAnimatedCoder safeAnimatedImageFrameAtIndex:] + 4333958952
21 App                        0x2d76c0 -[SDImageIOAnimatedCoder animatedImageFrameAtIndex:] + 4333958848
22 App                        0x2c4608 -[SDAnimatedImage initWithAnimatedCoder:scale:] + 4333880840
23 App                        0x2c44b8 -[SDAnimatedImage initWithData:scale:options:] + 4333880504
24 App                        0x2d8aac SDImageLoaderDecodeImageData + 4333963948
25 App                        0x2e0578 __95-[SDWebImageDownloaderOperation startCoderOperationWithImageData:pendingTokens:finishedTokens:]_block_invoke + 4333995384
26 Foundation                     0x9cee8 __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 16
27 Foundation                     0x73bbc -[NSBlockOperation main] + 100
28 Foundation                     0x73b50 __NSOPERATION_IS_INVOKING_MAIN__ + 12
29 Foundation                     0x38c10 -[NSOperation start] + 684
30 Foundation                     0x3895c __NSOPERATIONQUEUE_IS_STARTING_AN_OPERATION__ + 12
31 Foundation                     0x3d9fc __NSOQSchedule_f + 168
32 libdispatch.dylib              0x46630 _dispatch_block_async_invoke2 + 104
33 libdispatch.dylib              0x64780 _dispatch_client_callout + 16
34 libdispatch.dylib              0x3bd48 _dispatch_continuation_pop$VARIANT$armv81 + 436
35 libdispatch.dylib              0x3b480 _dispatch_async_redirect_invoke + 580
36 libdispatch.dylib              0x48c68 _dispatch_root_queue_drain + 328
37 libdispatch.dylib              0x49430 _dispatch_worker_thread2 + 160
38 libsystem_pthread.dylib        0x1b94 _pthread_wqthread + 224
39 libsystem_pthread.dylib        0x1720 start_wqthread + 8
Crashed: com.hackemist.SDImageFramePool.fetchQueue (QOS: UNSPECIFIED)
0  libsystem_platform.dylib       0x109c _platform_memmove + 76
1  ImageIO                        0x1e94d8 GIFBufferInfo::GIFBufferInfo(unsigned char*, bool, unsigned int, unsigned int, unsigned int) + 108
2  ImageIO                        0x1faf94 std::__1::__shared_ptr_emplace<GIFBufferInfo, std::__1::allocator<GIFBufferInfo> >::__shared_ptr_emplace[abi:v15006]<unsigned char*&, bool, unsigned int&, unsigned int&, unsigned int>(std::__1::allocator<GIFBufferInfo>, unsigned char*&, bool&&, unsigned int&, unsigned int&, unsigned int&&) + 76
3  ImageIO                        0x1faf14 std::__1::shared_ptr<GIFBufferInfo> std::__1::allocate_shared[abi:v15006]<GIFBufferInfo, std::__1::allocator<GIFBufferInfo>, unsigned char*&, bool, unsigned int&, unsigned int&, unsigned int, void>(std::__1::allocator<GIFBufferInfo> const&, unsigned char*&, bool&&, unsigned int&, unsigned int&, unsigned int&&) + 88
4  ImageIO                        0x1fa7a8 GIFReadPlugin::copyImageBlockSet(InfoRec*, CGImageProvider*, CGRect, CGSize, __CFDictionary const*) + 820
5  ImageIO                        0x1a270 IIO_Reader::CopyImageBlockSetProc(void*, CGImageProvider*, CGRect, CGSize, __CFDictionary const*) + 280
6  ImageIO                        0x15d20 IIOImageProviderInfo::copyImageBlockSetWithOptions(CGImageProvider*, CGRect, CGSize, __CFDictionary const*) + 744
7  ImageIO                        0x1ddf8 IIOImageProviderInfo::CopyImageBlockSetWithOptions(void*, CGImageProvider*, CGRect, CGSize, __CFDictionary const*) + 844
8  CoreGraphics                   0x42988 imageProvider_retain_data + 92
9  CoreGraphics                   0x6071c CGDataProviderRetainData + 80
10 CoreGraphics                   0x7d3a4 provider_for_destination_retain_data + 28
11 CoreGraphics                   0x6071c CGDataProviderRetainData + 80
12 CoreGraphics                   0x3f6e4 CGAccessSessionCreate + 108
13 CoreGraphics                   0xc30c img_data_lock + 2404
14 CoreGraphics                   0x516e0 CGSImageDataLock + 1328
15 CoreGraphics                   0x243f0 ripc_AcquireRIPImageData + 712
16 CoreGraphics                   0x41b58 ripc_DrawImage + 824
17 CoreGraphics                   0x184c0 CGContextDrawImageWithOptions + 1120
18 App                        0x2d2a70 +[SDImageCoderHelper CGImageCreateDecoded:orientation:] + 4341557872
19 App                        0x2d5b04 +[SDImageIOAnimatedCoder createFrameAtIndex:source:scale:preserveAspectRatio:thumbnailSize:lazyDecode:animatedImage:] + 4341570308
20 App                        0x2d7728 -[SDImageIOAnimatedCoder safeAnimatedImageFrameAtIndex:] + 4341577512
21 App                        0x2d76c0 -[SDImageIOAnimatedCoder animatedImageFrameAtIndex:] + 4341577408
22 App                        0x2c4d7c -[SDAnimatedImage animatedImageFrameAtIndex:] + 4341501308
23 App                        0x2f2820 __41-[SDImageFramePool prefetchFrameAtIndex:]_block_invoke + 4341688352
24 Foundation                     0xa6ef4 __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 24
25 Foundation                     0x7b000 -[NSBlockOperation main] + 104
26 Foundation                     0x7af90 __NSOPERATION_IS_INVOKING_MAIN__ + 16
27 Foundation                     0x3c4b8 -[NSOperation start] + 708
28 Foundation                     0x3c1ec __NSOPERATIONQUEUE_IS_STARTING_AN_OPERATION__ + 16
29 Foundation                     0x4187c __NSOQSchedule_f + 172
30 libdispatch.dylib              0x12fc4 _dispatch_block_async_invoke2 + 148
31 libdispatch.dylib              0x3eac _dispatch_client_callout + 20
32 libdispatch.dylib              0x7330 _dispatch_continuation_pop + 504
33 libdispatch.dylib              0x6998 _dispatch_async_redirect_invoke + 584
34 libdispatch.dylib              0x15944 _dispatch_root_queue_drain + 396
35 libdispatch.dylib              0x16158 _dispatch_worker_thread2 + 164
36 libsystem_pthread.dylib        0xda0 _pthread_wqthread + 228
37 libsystem_pthread.dylib        0xb7c start_wqthread + 8

@dreampiggy
Copy link
Contributor

dreampiggy commented Nov 16, 2023

standard OOM issue...

If your App has a limit RAM footprint, you can disable the force decode for image loading context[SDWebImageContextImageForceDecodePolicy] = @(SDImageForceDecodePolicyNever)

@dreampiggy dreampiggy added the OOM label Nov 16, 2023
@tac-han
Copy link
Author

tac-han commented Nov 17, 2023

standard OOM issue...

If your App has a limit RAM footprint, you can disable the force decode for image loading context[SDWebImageContextImageForceDecodePolicy] = @(SDImageForceDecodePolicyNever)

“If your App has a limit RAM footprint”, you mean that SDImageCache.shared.config.maxMemoryCost = UInt(1024 * 1024 * 100)?
Actually, most images in the app need to be displayed immediately after loading, such as cover images in a list. I understand that in such cases, deferred decoding should have little effect. Moreover, deferred decoding would increase the time it takes for users to see the images for the first time, which is not the desired effect.

Are there any other solutions?
Thanks

@dreampiggy
Copy link
Contributor

dreampiggy commented Nov 17, 2023

Moreover, deferred decoding would increase the time it takes for users to see the images for the first time

Yes

Most images in the app need to be displayed immediately after loading, such as cover images in a list

Maybe no. Because if we don't use Force Decode, ImageIO decoder will return a lazy CGImage, which only occupy RAM when display on the screen (CALayer trigger the actual CGDataProviderRetainBytePtr to allocate bitmap buffer, and CGDataProviderReleaseBytePtr when not used to free bitmap buffer).

You can try to disable the force decode firstly to see the memory footprint usage.

Then, if this still not enough, try using the thumbnail decoding feature to limit the big image size: SDWebImageContextImageThumbnailPixelSize, which suggested to pass the ImageView's size (convert to pixel, self.view.size * UIScreen.mainScreen.scale)

Maybe useful: https://github.com/SDWebImage/SDWebImage/wiki/Common-Problems#configuration-to-reduce-memory-pressure-aggressive

@tac-han
Copy link
Author

tac-han commented Nov 17, 2023

Ok, I will try it.

Then, if this still not enough, try using the thumbnail decoding feature to limit the big image size: SDWebImageContextImageThumbnailPixelSize, which suggested to pass the ImageView's size (convert to pixel, self.view.size * UIScreen.mainScreen.scale)

I see that there is mention of GIF in the crash stack. This method might not have a significant impact on GIF images because the issue with GIFs is often related to a large number of frames rather than the size.
Whether The suitability of Force Decode for GIFs?
Whether it increases the considerable time for users to see them for the first time.

@dreampiggy
Copy link
Contributor

dreampiggy commented Nov 17, 2023

Just have a try.

There are also another default control. The SDImageDecocdeUseLazyDecode set to true for SDAnimatedImage, which set to false for UIImage.

You can change this value as well to see the differenes. Which effect the frame rate as well.

@tac-han tac-han closed this as completed Nov 21, 2023
@tac-han tac-han reopened this Nov 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants