SDWebImage / SDWebImageSwiftUI

SwiftUI Image loading and Animation framework powered by SDWebImage
https://sdwebimage.github.io/SDWebImageSwiftUI
MIT License
2.14k stars 219 forks source link

Crash: Simultaneous accesses to 0x12d2205e0, but modification requires exclusive access #202

Closed abdelmagied94 closed 8 months ago

abdelmagied94 commented 2 years ago

Xcode 13.0 iOS 15.0.2

The crash happens with me when setting the isAnimating to .constant(false). It happens when setting the currentFrame to nil which I think publishes an update. Solved the issue by checking if the currentFrame is not nil before nullifying it. Actually I don't have an idea why we should set it to nil in the deinit.

Screen Shot 2021-11-01 at 4 01 53 PM
Thread #1, queue = 'com.apple.main-thread', stop reason = Simultaneous accesses to 0x12d2205e0, but modification requires exclusive access
    frame #0: 0x000000018634ccf4 libswiftCore.dylib`_swift_runtime_on_report
    frame #1: 0x000000018634d3ac libswiftCore.dylib`swift_beginAccess + 648
    frame #2: 0x0000000189c588c8 SwiftUI`SwiftUI.GraphHost.isValid.getter : Swift.Bool + 28
    frame #3: 0x0000000189017744 SwiftUI`generic specialization <SwiftUI.InvalidatingGraphMutation> of SwiftUI.GraphHost.asyncTransaction<τ_0_0 where τ_0_0: SwiftUI.GraphMutation>(_: SwiftUI.Transaction, mutation: τ_0_0, style: SwiftUI._GraphMutation_Style, mayDeferUpdate: Swift.Bool) -> () + 28
    frame #4: 0x000000018901e35c SwiftUI`SwiftUI.AttributeInvalidatingSubscriber.invalidateAttribute() -> () + 268
    frame #5: 0x0000000188fe9124 SwiftUI`SwiftUI.AttributeInvalidatingSubscriber.receive(τ_0_0.Output) -> Combine.Subscribers.Demand + 104
    frame #6: 0x00000001891870c4 SwiftUI`protocol witness for Combine.Subscriber.receive(τ_0_0.Input) -> Combine.Subscribers.Demand in conformance SwiftUI.AttributeInvalidatingSubscriber<τ_0_0> : Combine.Subscriber in SwiftUI + 24
    frame #7: 0x0000000188fe9f8c SwiftUI`SwiftUI.SubscriptionLifetime.Connection.receive(τ_0_0.Output) -> Combine.Subscribers.Demand + 244
    frame #8: 0x0000000198f10854 Combine`Combine.ObservableObjectPublisher.Inner.send() -> () + 204
    frame #9: 0x0000000198f28eb4 Combine`Combine.ObservableObjectPublisher.send() -> () + 552
    frame #10: 0x0000000198f1bb10 Combine`Combine.PublishedSubject.send(τ_0_0) -> () + 160
    frame #11: 0x0000000198f05390 Combine`function signature specialization <Arg[1] = Owned To Guaranteed, Arg[2] = Dead, Arg[3] = Owned To Guaranteed, Arg[4] = Dead> of static Combine.Published.subscript.setter : <τ_0_0 where τ_1_0: AnyObject>(_enclosingInstance: τ_1_0, wrapped: Swift.ReferenceWritableKeyPath<τ_1_0, τ_0_0>, storage: Swift.ReferenceWritableKeyPath<τ_1_0, Combine.Published<τ_0_0>>) -> τ_0_0 + 620
    frame #12: 0x0000000198f0688c Combine`static Combine.Published.subscript.setter : <τ_0_0 where τ_1_0: AnyObject>(_enclosingInstance: τ_1_0, wrapped: Swift.ReferenceWritableKeyPath<τ_1_0, τ_0_0>, storage: Swift.ReferenceWritableKeyPath<τ_1_0, Combine.Published<τ_0_0>>) -> τ_0_0 + 40
    frame #13: 0x00000001092b270c SDWebImageSwiftUI`ImagePlayer.currentFrame.setter(value=nil, self=0x00000002803c5f80) at ImagePlayer.swift:0
  * frame #14: 0x00000001092b25d4 SDWebImageSwiftUI`ImagePlayer.deinit(self=0x00000002803c5f80) at ImagePlayer.swift:34:22
    frame #15: 0x00000001092b2788 SDWebImageSwiftUI`ImagePlayer.__deallocating_deinit(self=0x00000002803c5f80) at ImagePlayer.swift:0
    frame #16: 0x000000018634fde0 libswiftCore.dylib`_swift_release_dealloc + 56
    frame #17: 0x00000001092c8fbc SDWebImageSwiftUI`destroy for WebImage at <compiler-generated>:0
    frame #18: 0x0000000188ffd5b0 SwiftUI`destroy value witness for SwiftUI.ModifiedContent + 72
    frame #19: 0x0000000188ffd5b0 SwiftUI`destroy value witness for SwiftUI.ModifiedContent + 72
    frame #20: 0x00000001b29c6aa8 AttributeGraph`AG::Node::destroy(AG::Graph&) + 152
    frame #21: 0x00000001b29c65d4 AttributeGraph`AG::Subgraph::invalidate_now(AG::Graph&, unsigned long) + 1272
    frame #22: 0x00000001b29c2728 AttributeGraph`AG::Graph::invalidate_subgraphs() + 184
    frame #23: 0x00000001b29cc138 AttributeGraph`AG::Graph::Context::~Context() + 276
    frame #24: 0x00000001b29cac20 AttributeGraph`AGGraphInvalidate + 36
    frame #25: 0x00000001890e5f9c SwiftUI`SwiftUI.GraphHost.invalidate() -> () + 168
    frame #26: 0x000000018902f7d4 SwiftUI`closure #1 () -> () in SwiftUI._UIHostingView.deinit + 84
    frame #27: 0x0000000189029df8 SwiftUI`SwiftUI._UIHostingView.__deallocating_deinit + 228
    frame #28: 0x0000000189034de4 SwiftUI`@objc SwiftUI._UIHostingView.__deallocating_deinit + 28
    frame #29: 0x00000001815a8960 CoreFoundation`__RELEASE_OBJECTS_IN_THE_ARRAY__ + 116
    frame #30: 0x00000001815bc64c CoreFoundation`-[__NSArrayM dealloc] + 276
    frame #31: 0x0000000199b3f55c libobjc.A.dylib`AutoreleasePoolPage::releaseUntil(objc_object**) + 200
    frame #32: 0x0000000199b3b928 libobjc.A.dylib`objc_autoreleasePoolPop + 208
    frame #33: 0x0000000185332128 QuartzCore`CA::Context::commit_transaction(CA::Transaction*, double, double*) + 620
    frame #34: 0x000000018533b174 QuartzCore`CA::Transaction::commit() + 680
    frame #35: 0x000000018531d210 QuartzCore`CA::Transaction::flush_as_runloop_observer(bool) + 88
    frame #36: 0x00000001815db570 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 36
    frame #37: 0x00000001815aa854 CoreFoundation`__CFRunLoopDoObservers + 572
    frame #38: 0x00000001815a58ec CoreFoundation`__CFRunLoopRun + 1052
    frame #39: 0x00000001815b93c8 CoreFoundation`CFRunLoopRunSpecific + 600
    frame #40: 0x000000019cdca38c GraphicsServices`GSEventRunModal + 164
    frame #41: 0x0000000183f5f060 UIKitCore`-[UIApplication _run] + 1100
    frame #42: 0x0000000183cdcb8c UIKitCore`UIApplicationMain + 2124
    frame #43: 0x0000000104de2500 Haraj`main(argc=1, argv=0x000000016b023918) at main.m:15:17
    frame #44: 0x0000000106f41a24 dyld`start + 520
bryant81pts commented 2 years ago

I have exactly the same problem besides the crash still happen occasionally even if I don't set the isAnimating parameter.

jarrencampos commented 1 year ago

I am still having this issue, randomly crashes the app.

angelmic commented 10 months ago

I have exactly the same problem besides the crash still happen occasionally even if I don't set the isAnimating parameter.

dreampiggy commented 10 months ago

Seems TSAN issue.

@angelmic Can you have a test with v3.0.0-beta is this still reproducable ?

irfanabdulkhaliq commented 8 months ago

I am facing same issue any solution ?

dreampiggy commented 8 months ago

@irfanabdulkhaliq

This code no longer exists ? There are no deinit

Try with 3.0.0-beta2 with reproducable demo ?

irfanabdulkhaliq commented 8 months ago

how to try or install 3.0.0-beta2 on my project @dreampiggy

irfanabdulkhaliq commented 8 months ago

I have installed 2.2.5 and still no crash has produced yet only code exist in imagePlayer file deinit { player?.stopPlaying() }

dreampiggy commented 8 months ago

how to try or install 3.0.0-beta2 on my project @dreampiggy

Just use the fixed version ? As a App developer, you have final control for each package's version.

That's semver is for SDK developer, not App developer. So, as an App developer (not me as SDK developer), you'd better using the fixed version always (to avoid automatically updated)

dreampiggy commented 8 months ago

https://developer.apple.com/documentation/xcode/adding-package-dependencies-to-your-app

dreampiggy commented 8 months ago

Try with v2.2.6 and see whether this been fixed or not.

If you don't have time to try v3.0.0

In v3.0.0, this repo may move to SDWebImage Core repo...So which need some migration (not pain, but still need changing the Podfile or Package.swift)

irfanabdulkhaliq commented 8 months ago

v2.2.6 updated and crashed has been fixed. Thank you @dreampiggy