neekeetab / CachingPlayerItem

Play and cache media content simultaneously on your iOS device
MIT License
520 stars 89 forks source link

crash with fatalError "internal inconsistency" #9

Closed anneWe closed 6 years ago

anneWe commented 6 years ago

hey, thanks for your great library, we use it in our project to cache videos.

beginning with ios11 we have a crash that occurs very often with bad internet connection like edge (real edge, not faked edge with charles or the network link conditioner):

the fatalError in the AVAssetResourceLoader delegate shouldWaitForLoadingOfRequestedResource is triggered, because the owner property is nil

It seems like the AVAssetResourceLoader is keeping a reference to the custom ResourceLoaderDelegate, even if the CachingPlayerItem isn't existing anymore. with iOS 9 and 10 we don't see this crash. do you have any idea how to fix this?

thanks in advance!

neekeetab commented 6 years ago

The owner property won't be nil unless you keep a strong reference to CachingPlayerItem.resourceLoaderDelegate somewhere in your code. But that shouldn't be the case since CachingPlayerItem.resourceLoaderDelegate is declared as fileprivate. Generally speaking, you shouldn't interact with ResourceLoaderDelegate directly -- it's internal to CachingPlayerItem.

anneWe commented 6 years ago

I don't access the resourceLoaderDelegate property myself and therefore don't keep any strong references to it. I suppose the AVFoundation Framework itself still has a strong reference to the delegate. Not all the time, but only with ios11 and edge network.

neekeetab commented 6 years ago

It may be so. I wasn't able to reproduce the crash on iOS11 with edge playing mp3 file. You can provide me a sample project that reproduces it and I will take a look. Or you can try replacing fatalError("internal inconsistency") with return false, that should make it stop crashing.