JellyGif icon indicating copy to clipboard operation
JellyGif copied to clipboard

EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000010 JellyGifAnimator.prepareAnimation()

Open saritaOctal opened this issue 3 years ago • 12 comments

3 JellyGif 0xb728 partial apply for closure #2 in JellyGifAnimator.prepareAnimation() + 4316247848 (:4316247848) 4 JellyGif 0xae7c thunk for @escaping @callee_guaranteed () -> () + 4316245628 (:4316245628)

saritaOctal avatar Feb 02 '22 06:02 saritaOctal

I am also experiencing this crash. Any updates?

frcouceiro avatar Feb 14 '22 10:02 frcouceiro

JellyGifAnimator is using a serial queue (labelled "custom.jelly.gif.animator.queue") to async run JellyGifOperations whenever prepareAnimation is called. The crash seems related to Foundation.Operation internals:

 Crashed: custom.jelly.gif.animator.queue
 0  libobjc.A.dylib                0x2474 objc_msgSend + 20
 1  Foundation                     0x11fa6c +[__NSOperationInternalObserver _observeValueForKeyPath:ofObject:changeKind:oldValue:newValue:indexes:context:] + 356
 2  Foundation                     0x1def0 -[NSOperation start] + 1196
 3  JellyGif                       0xb764 partial apply for closure #2 in JellyGifAnimator.prepareAnimation() + 4321490788 (<compiler-generated>:4321490788)
 4  JellyGif                       0xaeb8 thunk for @escaping @callee_guaranteed () -> () + 4321488568 (<compiler-generated>:4321488568)

Since JellyGifOperation is not actually being run in Foundation.OperationQueue I made it a plain class (not extending Foundation.Operation) and I no longer have a crash. What you think? I will submit a PR to better illustrate what I am saying.

My use case is that I have a scrollable list with each cell using a JellyGifAnimator, so I assume that depending on user scrolling speed we may have a sequence of JellyGifAnimator.prepareAnimation() calls that can overlap each other. By using Foundation.Operation without Foundation.OperationQueue I am not sure how the internal state of each JellyGifOperation would play in this scenario --> this may be the crash root cause. Any idea?

frcouceiro avatar Feb 14 '22 12:02 frcouceiro

@saritaOctal can you try the fix using my fork and give feedback? If you are using CocoaPods:

 pod 'JellyGif', :git => 'https://github.com/frcouceiro/JellyGif.git'

frcouceiro avatar Feb 14 '22 13:02 frcouceiro

@frcouceiro Have experienced the same, have you found your fix to be reliable?

BDProject avatar Apr 11 '22 13:04 BDProject

@frcouceiro Have experienced the same, have you found your fix to be reliable?

I haven’t experienced new crashes since then. I would suggest you to debug and see if my solution makes sense to you and your problem. Since the PR has not been merged and did not get much attention we can not really attest it is now 100%. For me it fixed the problem entirely 🙂

frcouceiro avatar Apr 11 '22 17:04 frcouceiro

@frcouceiro That is good news. We've found away reliably make it crash, so I will try your branch and see if it fixes the issue on my side. If so maybe @TaLinh would be open to merging the PR?

BDProject avatar Apr 12 '22 11:04 BDProject

Just to follow up @frcouceiro, your branch fixed all our crash issues. 👍

BDProject avatar Apr 12 '22 17:04 BDProject

@frcouceiro Thanks for your contribution. I could not reproduce this crash. Can you describe it in more details? What is your iOS version, does this crash 100% of the time, and the steps to reproduce. Thanks again

TaLinh avatar Apr 13 '22 11:04 TaLinh

@frcouceiro Thanks for your contribution. I could not reproduce this crash. Can you described it with more details? What is your iOS version, does this crash 100% of the time, and the steps to reproduce. Thanks again

We could not repo when using a build from Xcode to the device. We could repo when sending the build to Testflight.

  • iPhone SE(1st Gen) would crash every time when showing a collection view of gifs.
  • iPhone 6s would crash every time when showing a collection view of gifs.
  • iPhone 11 would crash after about 15minutes of using the app
  • iPhone 13 would also crash 15+ minutes of using the app.

Stack trace would show it was coming from within JellyGif

Using the PR @frcouceiro opened would solve the issue and we could no longer repo.

Thanks @TaLinh for the work on this framework 👍

BDProject avatar Apr 13 '22 12:04 BDProject

Hi @BDProject, thank you so much for the detailed feedback. I did not have time to fully investigate but a quick fix is replacing DispatchQueue with OperationQueue and instead of calling the start function directly do JellyGifAnimator.gifQueue.addOperation(preparingOperation!).

public static var gifQueue = OperationQueue()

public func prepareAnimation() {
  stopPreparingAnimation()

  preparingOperation = JellyGifOperation(info: imageInfo, pixelSize: preferredPixelSize) { [weak self] images, frames in
    self?.setupWith(images: images, frames: frames)
      self?.preparingOperation = nil
  }

  JellyGifAnimator.gifQueue.addOperation(preparingOperation!)
}

I will look into this asap and possibly refactor JellyGifAnimator as it is coupled as @frcouceiro said. Thanks again

TaLinh avatar Apr 13 '22 12:04 TaLinh

@TaLinh - Hi, I'm also experiencing this crash. Any resolution for this?

Below attached is the screenshot for crash logs. Screenshot 2023-09-28 at 3 19 10 PM (2)

ghost avatar Sep 28 '23 10:09 ghost