Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash in AssetsViewController.photoLibraryDidChange #254

Closed
Haccoon opened this issue Apr 16, 2020 · 10 comments
Closed

Crash in AssetsViewController.photoLibraryDidChange #254

Haccoon opened this issue Apr 16, 2020 · 10 comments
Labels

Comments

@Haccoon
Copy link

Haccoon commented Apr 16, 2020

Hi! Thanks for such a great library.

When I switched the app to the background, and launched the camera app to take a picture, when I came back to the foreground, it crashed in AssetsViewController.photoLibraryDidChange(_:) every time.

The log is shown below.

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of items in section 0. The number of items contained in an existing section after the update (67) must be equal to the number of items contained in that section before the update (67), plus or minus the number of items inserted or deleted from that section (1 inserted, 0 deleted) and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out).

@mikaoj mikaoj added the bug label Apr 16, 2020
@Haccoon
Copy link
Author

Haccoon commented Apr 22, 2020

why use performBatchUpdates ?

Is there a problem if I only handle it with reloadData?

    func photoLibraryDidChange(_ changeInstance: PHChange) {
        guard let changes = changeInstance.changeDetails(for: fetchResult) else { return }
        // Since we are gonna update UI, make sure we are on main
        DispatchQueue.main.async {
            self.fetchResult = changes.fetchResultAfterChanges
            self.collectionView.reloadData()

            // No matter if we have incremental changes or not, sync the selections
            self.syncSelections(self.store.assets)
        }
    }

@mikaoj
Copy link
Owner

mikaoj commented Apr 22, 2020

It won't crash if you use reload data, sure.
However it won't look good. The UI will blink/glitch every time photoLibraryDidChange is called as it reload all cells instead of just updating those that have changed.

Put a breakpoint in the performBatchUpdates block and figure out what is going on. Does it have incremental changes? Does it have deleted, inserted or moved items? And are we updating the collection view with those changes.

I'll look into too whenever I have time.

@Haccoon
Copy link
Author

Haccoon commented Apr 22, 2020

If the UI blinking is the only problem, is it okay to take temporary action by using reloaddata first? Crash is a serious problem.

I'm still analyzing it with performanceBatchUpdates, but it's too difficult. ;(

@mikaoj
Copy link
Owner

mikaoj commented Apr 22, 2020

If you are fine with that.

  1. Fork this repo
  2. Make the fix
  3. Update your Podfile to use your fork until I've made a proper fix.
pod 'BSImagePicker', :git => 'https://github.com/Haccoon/BSImagePicker.git'

@mikaoj
Copy link
Owner

mikaoj commented Apr 22, 2020

So I just tried reproducing the crash, but it works for me.
Could you give me any more details?

  • Device
  • iOS version
  • Any special settings made to the image picker
  • Etc

@Haccoon
Copy link
Author

Haccoon commented Apr 23, 2020

  • iPhone SE
  • OS 12

I attach a reenactment video.
Photos taken with cameras should be added, but the app is crash.

Apr-23-2020 11-33-54

@mikaoj
Copy link
Owner

mikaoj commented Apr 23, 2020

Yeapp, reproducible on iOS 12. Thanks :)

@Haccoon
Copy link
Author

Haccoon commented Apr 23, 2020

Oh, this is not a crash that occurs only with iOS 12. It also happens in 13.

@mikaoj
Copy link
Owner

mikaoj commented Apr 23, 2020

Alright, worked for me on iOS 13 but crashes on iOS 12 :)

@mikaoj
Copy link
Owner

mikaoj commented Apr 23, 2020

Try 3.1.4 - it should be fixed now. Thanks for helping out :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants