-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Fix 'Take a Photo' option failing after adding an image to gallery block #14299
Conversation
You can trigger optional UI/connected tests for these changes by visiting CircleCI here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this and ran into a crash on step 4 of the test steps. The crash is on this line:
WordPress-iOS/WordPress/Classes/ViewRelated/Gutenberg/GutenbergMediaPickerHelper.swift
Line 137 in 5721e14
guard picker == navigationPicker?.mediaPicker else { |
and it reads:
Fatal error: Attempted to read an unowned reference but the object was already deallocated
it's referring to the navigationPicker
.
This crash only happens when you first pick a photo from the library—which initializes navigationPicker
—and then you take a photo, which causes navigationPicker
to be accessed.
This wouldn't be an issue except for the fact that navigationPicker
is an unowned reference, and is only retained while it is being presented on the screen. As soon as the navigationPicker
is dismissed, it's released. Then when you take a photo, navigationPicker
is accessed and crashes since it's now deallocated.
I think there's also a (minor) bug in WPMediaPicker because it probably shouldn't be calling its delegate method emptyViewController(forMediaPickerController:)
when a photo is taken since an empty state isn't applicable when taking a photo.
I'm not sure why this crash isn't closing the app in production, it must be caught somewhere 🤔. |
@guarani I couldn't reproduce the crash with debugger attached. Do you mean it happens selecting first from "Choose from device" or "Free Photo Library"? Both worked fine for me.
For me this method is not called when a photo is taken via "Take a Photo": Could it be an iOS or Xcode version difference? I'm using iOS 13.5.1 and Xcode 11.5? Can you please try again maybe with the build in this comment? It also worked fine for me. |
Hey @ceyhun, it happened to me when selecting "Choose from device".
It's strange this method is being called on my device but not on yours.
I was also on Xcode 11.5, but my device was on iOS 13.4.1.
I should have mentioned I tested build 29996 yesterday. Although I'll try the new 30055 now. Just tested 30055 and it's crashing (closing) the app for me. It happens when using just the gallery block (first photo from device gallery, second photo captured by camera), or when using two image blocks (again, first from device gallery, second from camera). I'm going to update my device to the latest iOS and try again. |
I've updated to 13.5.1 and still see the crash, both with the current App Store version and build 30055. I tried to follow the exact sequence of steps you performed in the gif above but the second image in the gallery never gets added for me (or crashes the app if I'm on build 30055 instead of the App Store version). If we were to try to implement a fix at the moment, I think changing WordPress-iOS/WordPress/Classes/ViewRelated/Gutenberg/GutenbergMediaPickerHelper.swift Line 19 in 5721e14
because this will allow navigationPicker to become nil and no longer crash the app when accessed from emptyViewController(forMediaPickerController:) . We could take this one step further and leave it as a plain optional (no weak or unowned). (WPNavigationMediaPickerViewController is used in a bunch of places in the app and in none of them is it unowned or weak .)
I know this must be awkward to debug since it's not crashing on your end, but I thought I'd mention this fix since 15.1 is getting cut on Monday. |
@SergioEstevao – do you know why this is a weak reference (it crashes the gallery block on some devices but not others)? WordPress-iOS/WordPress/Classes/ViewRelated/Gutenberg/GutenbergMediaPickerHelper.swift Line 19 in 5721e14
|
I'm assuming it was to avoid a retain cycle, but is this reference being used after the picker is dismissed? I normally prefer to use a weak references to avoid unexpected crashes when accessing it references after releases. |
@SergioEstevao yes, this crashes on some devices because it gets accessed after being deallocated. |
@guarani I agree with that. Just made this change. But this still makes me think what could be the reason that make this crash for you and not me 🤔 |
Howdy friends – we're freezing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@guarani I agree with that. Just made this change. But this still makes me think what could be the reason that make this crash for you and not me 🤔
I'm not sure either to be honest. It's weird that emptyViewController is not called for you AFAIK, but it's called for me. Consider this scenario: when I go to take a photo, a WPMediaPickerViewController
instance is instanciated and assigned to cameraPicker
(which makes sense), then I take a photo, tap Use Photo on the camera screen, then as the camera modal screen is dismissed I see that viewDidLoad is called on the same cameraPicker object (same memory address). Not sure why that's happening.
Anyhow, I tested with the latest build and it works as expected 👍 .
@guarani Thanks for testing again 🙇 Good to hear that it's fixed now! The crash you had could be this one: https://sentry.io/organizations/a8c/issues/1535683817/?project=1438083 |
Fixes wordpress-mobile/gutenberg-mobile#1965
Could potentially fix https://sentry.io/organizations/a8c/issues/1535683817/?project=1438083
To test:
PR submission checklist:
RELEASE-NOTES.txt
if necessary.