3 Replies
      Latest reply on Oct 28, 2018 3:32 AM by Leon1024
      xaphod Level 1 Level 1 (0 points)

        I have a popular app and i'm seeing a sporadic crash that I don't understand:

         

        Fatal Exception: NSInternalInconsistencyException
        This method can only be called from inside of -[PHPhotoLibrary performChanges:completionHandler:] or -[PHPhotoLibrary performChangesAndWait:error:]

         

        Here is the code, it crashes on line 3 (creationRequestForAssetFromImage) below:

         

               PHPhotoLibrary.shared().performChanges({
                    guard
                        let changeRequest = PHAssetChangeRequest.creationRequestForAssetFromImage(atFileURL: animatedImageFileURL),
                        let albumChangeRequest = PHAssetCollectionChangeRequest.init(for: album),
                        let placeholder = changeRequest.placeholderForCreatedAsset else {
                            WLog("ActionExecuter: error, couldn't init creationRequests")
                            completionBlock(nil)
                            return
                    }
        ...

         

        Clearly this IS in a performChanges block.

         

        Full stack of crash, from line 3 above onwards:

         

        Fatal Exception: NSInternalInconsistencyException
        0  CoreFoundation                 0x184da6d8c __exceptionPreprocess
        1  libobjc.A.dylib                0x183f605ec objc_exception_throw
        2  Photos                         0x193cad220 -[PHPhotoLibrary recordInsertRequest:]
        3  Photos                         0x193c3cf78 -[PHChangeRequestHelper initForNewObjectWithUUID:changeRequest:]
        4  Photos                         0x193c6dfc4 -[PHAssetCreationRequest initForNewObjectWithUUID:]
        5  Photos                         0x193c699c0 +[PHAssetCreationRequest _creationRequestForAssetUsingUUID:]
        6  Photos                         0x193c69ce4 +[PHAssetCreationRequest creationRequestForAssetFromImageAtFileURL:]
        

         

        I am wondering if this is some threading issue. Is there a rule about what thread performChanges et al have to be called from?

         

        It seems to be slower devices that hit this: iOS 11 on an iPad Air 1 is the latest crash in the wild I saw of this one.

        Thanks for any help