yeatse / KingfisherWebP

Elegantly handle WebP format with Kingfisher.
MIT License
304 stars 73 forks source link

Occasional crash at WebPImageCreateWithData #55

Closed kimi14314 closed 1 year ago

kimi14314 commented 3 years ago

Met an unusual crash. 企业微信截图_e985df83-d1bf-4593-a38d-576ee20e4316

Any idea on what happened?

kimi14314 commented 3 years ago

企业微信截图_99157848-852a-47de-a55d-c8f43127d61f

Crashed here

skyxian commented 3 years ago

企业微信截图_99157848-852a-47de-a55d-c8f43127d61f

Crashed here

Hello, have you solved this problem? I also encountered this problem, can you tell me how to solve it?

kimi14314 commented 3 years ago

企业微信截图_99157848-852a-47de-a55d-c8f43127d61f Crashed here

Hello, have you solved this problem? I also encountered this problem, can you tell me how to solve it?

Hello, I tried to upgrade libwep to v1.2.0, but I am not sure if the problem could be solved since it's an unusual crash. Need to observe for a while

yeatse commented 3 years ago

@skyxian @kimi14314 At what probability does it happen in production? I need more information to investigate into it, such as os version, more detailed stack traces etc.

kimi14314 commented 3 years ago

image image "EXC_BAD_ACCESS · Attempted to dereference null pointer" Seems to be a multi-thread problem. Probability is about 1% in production.

 

"

sunSink commented 3 years ago

Has this problem been solved? I also encountered this problem in production(KingfisherWebP version = 1.3.0 ,device model: = iPhone 8p,os = 14.7.1), but i couldn't reproduce.

image

yeatse commented 3 years ago

Has this problem been solved? I also encountered this problem in production(KingfisherWebP version = 1.3.0 ,device model: = iPhone 8p,os = 14.7.1), but i couldn't reproduce.

image

It shouldn't be a multithreaded problem, since webp decoding is totally a blocking operation. From this stack trace I assume it might be caused by some memory pressure. How much memory used and left on the device when this crash occurred?

sunSink commented 3 years ago

Has this problem been solved? I also encountered this problem in production(KingfisherWebP version = 1.3.0 ,device model: = iPhone 8p,os = 14.7.1), but i couldn't reproduce. image

It shouldn't be a multithreaded problem, since webp decoding is totally a blocking operation. From this stack trace I assume it might be caused by some memory pressure. How much memory used and left on the device when this crash occurred?

image

Thanks!

Your guess may be correct.

chenfei533 commented 2 years ago

这个问题解决了吗?我在生产中也遇到过这个问题(KingfisherWebP version = 1.3.0 ,device model: = iPhone 8p,os = 14.7.1),但无法重现。 图片

它不应该是一个多线程问题,因为 webp 解码完全是一个阻塞操作。从这个堆栈跟踪我认为它可能是由一些内存压力引起的。发生此崩溃时,设备上已使用和剩余多少内存?

图片

谢谢!

你的猜测可能是正确的。

is there any solution,When the memory is low

pengpai commented 1 year ago

any update here? same issue at low memory case

skyxian commented 1 year ago

Previously, the use of webp was closed due to a crash. After the recent two versions were opened, this crash ranks in the top two positions. I can provide the following information. Can the author help analyze how to solve it?,thanks

BIFpcsepYF

UISWKj7M4b GkY0DSCkEW w4r6ZgROS3 JKMwDRgXMo vCfVwvmhDU

The crash seems to have occurred in models below iphoneXR,And it all happens in the WebPAnimDecoderDelete(dec) method @yeatse

yeatse commented 1 year ago

Actually this crash comes from the previous line: memcpy(bufCopy, buf, bufsize);. As we discussed earlier, this is fundamentally an out-of-memory issue, that we failed to copy the decoded image buffer for future use. In my personal experience, memory issues are more likely to occur on devices with 3GB RAM. For more details on this topic, please refer to this article.

To resolve this crash and prevent similar issues in the future, you should pay close attention to your app's overall memory usage. Here are a couple of methods that can help:

  1. Set Kingfisher's memory cache to a lower limit: https://github.com/onevcat/Kingfisher/wiki/Cheat-Sheet#cache
  2. Add a ResizingImageProcessor after WebPProcessor to downscale your result image

I will release a new version later that returns a null image instead of crashing when low memory occurs; however, it is still important for you to implement these changes.

@skyxian

skyxian commented 1 year ago

Actually this crash comes from the previous line: memcpy(bufCopy, buf, bufsize);. As we discussed earlier, this is fundamentally an out-of-memory issue, that we failed to copy the decoded image buffer for future use. In my personal experience, memory issues are more likely to occur on devices with 3GB RAM. For more details on this topic, please refer to this article.

To resolve this crash and prevent similar issues in the future, you should pay close attention to your app's overall memory usage. Here are a couple of methods that can help:

  1. Set Kingfisher's memory cache to a lower limit: https://github.com/onevcat/Kingfisher/wiki/Cheat-Sheet#cache
  2. Add a ResizingImageProcessor after WebPProcessor to downscale your result image

I will release a new version later that returns a null image instead of crashing when low memory occurs; however, it is still important for you to implement these changes.

@skyxian

Thank you very much, I will modify the existing code according to your suggestion, and look forward to your new release version

@yeatse

yeatse commented 1 year ago

Released 1.4.1

chenfei533 commented 1 year ago

现实上这个崩溃来自上一步:以memcpy(bufCopy, buf, bufsize);备将来使用。根据我的个人经验,内存问题更可能发生在配备了3GB RAM的设备上。有关于此主题的更多详细信息,请参阅附件

要解决此崩溃并阻止将出现类似问题,您应该密切注意应用的整体内存使用情况。以下是一些可以提供帮助的方法法:

  1. 将 Kingfisher 的内部存储设置为下载:https ://github.com/onevcat/Kingfisher/wiki/Cheat-Sheet#cache
  2. 添加一个ResizingImageProcessorafterWebPProcessor以缩小小结果图像

之后我会发布一个新版本,它会返回一个空间图像,而不是在内存不及时崩溃;但是,实际应用这些更改对您来说仍然很重要要。

@skyxian

"添加一个ResizingImageProcessorafterWebPProcessor以缩小小结果图像"

是这样设置吗:

options?.append(.processor(ResizingImageProcessor(referenceSize: size))) options?.append(.processor(WebPProcessor.default))

yeatse commented 1 year ago

现实上这个崩溃来自上一步:以memcpy(bufCopy, buf, bufsize);备将来使用。根据我的个人经验,内存问题更可能发生在配备了3GB RAM的设备上。有关于此主题的更多详细信息,请参阅附件。 要解决此崩溃并阻止将出现类似问题,您应该密切注意应用的整体内存使用情况。以下是一些可以提供帮助的方法法:

  1. 将 Kingfisher 的内部存储设置为下载:https ://github.com/onevcat/Kingfisher/wiki/Cheat-Sheet#cache
  2. 添加一个ResizingImageProcessorafterWebPProcessor以缩小小结果图像

之后我会发布一个新版本,它会返回一个空间图像,而不是在内存不及时崩溃;但是,实际应用这些更改对您来说仍然很重要要。 @skyxian

"添加一个ResizingImageProcessorafterWebPProcessor以缩小小结果图像"

是这样设置吗:

options?.append(.processor(ResizingImageProcessor(referenceSize: size))) options?.append(.processor(WebPProcessor.default))

参考:https://github.com/onevcat/Kingfisher/wiki/Cheat-Sheet#multiple-processors Resizing 放 WebP 后面

chenfei533 commented 1 year ago

这两个调换下先后 webp动图就不动了

yeatse commented 1 year ago

这两个调换下先后 webp动图就不动了

1.5.2 版本之后动图可以使用 AnimatedImageView 了,会自动根据 View 的实际大小压缩图片