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

2.10Alpha54: Crash when pressing "edit field" for img field #5856

Closed
Anthropos888 opened this issue Mar 23, 2020 · 13 comments · Fixed by #5857
Closed

2.10Alpha54: Crash when pressing "edit field" for img field #5856

Anthropos888 opened this issue Mar 23, 2020 · 13 comments · Fixed by #5857

Comments

@Anthropos888
Copy link
Contributor

Reproduction Steps
  1. Review a card with an image
  2. Go to the edit card screen
  3. Tap the paper clip icon (edit field) next to the img field
Expected Result

The edit field screen with the image is shown

Actual Result

(Soft) Crash. A report is being sent and AnkiDroid returns to the reviewer.

I think I'll downgrade to alpha53 for now since I can't view/change images anymore from the edit card screen.

Debug info

AnkiDroid Version = 2.10alpha54

Android Version = 9

ACRA UUID = 1f29f610-893a-403f-83d5-25a26ba97fe0

Research

Enter an [ x ] character to confirm the points below:

[X ] I have read the support page and am reporting a bug or enhancement request specific to AnkiDroid

[ x] I have checked the manual and the FAQ and could not find a solution to my issue

[ x ] I have searched for similar existing issues here and on the user forum

@Anthropos888
Copy link
Contributor Author

Check database and check media didn't solve the problem.

I downgraded to 2.10alpha53 and now everything is working again.

@david-allison
Copy link
Member

Ack... this one is almost certainly on me. Thanks for the catch.

Possible refs: #5849, #5841

@david-allison
Copy link
Member

#5849

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ichi2.anki/com.ichi2.anki.multimediacard.activity.MultimediaEditFieldActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setVisibility(int)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2928)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3063)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1823)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:198)
at android.app.ActivityThread.main(ActivityThread.java:6729)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setVisibility(int)' on a null object reference
at com.ichi2.anki.multimediacard.fields.BasicImageFieldController.setPreviewImage(BasicImageFieldController.java:6)
at com.ichi2.anki.multimediacard.fields.BasicImageFieldController.createUI(BasicImageFieldController.java:6)
at com.ichi2.anki.multimediacard.activity.MultimediaEditFieldActivity.recreateEditingUi(MultimediaEditFieldActivity.java:15)
at com.ichi2.anki.multimediacard.activity.MultimediaEditFieldActivity.onCreate(MultimediaEditFieldActivity.java:11)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1272)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2908)
... 11 more

@Anthropos888
Copy link
Contributor Author

@david-allison-1
It seems you enhanced the Editing Field screen for images? Nice, unfortunately I can't test it due to the bug. I had one more issue with the editing field screen for images long time ago: #5192

What do you think how complicated it is to have a "rename" feature there?

@david-allison
Copy link
Member

@Anthropos888,

Assuming one image? More annoying than you'd expect, we'd need to synchronise both the file rename, and the saving of the note, and rollback if one fails.

That being said, if it's on the backlog, it's visible and it's possible

@david-allison
Copy link
Member

Testing a fix for this now, should be a PR in 10

david-allison added a commit to david-allison/Anki-Android that referenced this issue Mar 23, 2020
When loading an existing image, we performed the image load before we
had created all elements of the UI. This caused issues.

We fix this by splitting UI creation and initialisation logic
david-allison added a commit to david-allison/Anki-Android that referenced this issue Mar 23, 2020
createUI has `@SuppressLint("NewApi")` due to camera permissioning,
but it masked a bug in calling setBackground with lower API levels
mikehardy pushed a commit that referenced this issue Mar 24, 2020
* Fix #5856 - Image Preview Crash

When loading an existing image, we performed the image load before we
had created all elements of the UI. This caused issues.

We fix this by splitting UI creation and initialisation logic

* Fix #5856 - Fix API Errors

createUI has `@SuppressLint("NewApi")` due to camera permissioning,
but it masked a bug in calling setBackground with lower API levels

* Added Unit Tests

Very basic right now, but there's a lot of value in ensuring that a
screen can be created with no errors.
@mikehardy
Copy link
Member

2.10alpha55 is out with the fix, as soon as Google is done processing it and starts delivery...

@Anthropos888
Copy link
Contributor Author

Problem solved in 2.10alpha56. Thanks @david-allison-1 BTW showing the image size in the editing field screen is really useful!

@david-allison
Copy link
Member

Problem solved in 2.10alpha56. Thanks @david-allison-1 BTW showing the image size in the editing field screen is really useful!

No worries! Good to hear!

To be honest: the functionality is almost accidental. It's the best way to tell someone the impact if there's a problem with "compress & resize", but it might as well be enabled for all images.

@Anthropos888
Copy link
Contributor Author

@david-allison-1 what do you mean with "compress & resize"? Is that a new feature in development?

@david-allison
Copy link
Member

david-allison commented Mar 25, 2020

@david-allison-1 what do you mean with "compress & resize"? Is that a new feature in development?

It's been a feature since 2014: 7c0811c. Whenever someone takes a picture with the camera, we try to silently compress and resize it so it doesn't take up too much disk space.

Sadly, this occasionally fails: #5513/#5849 (hence the bugfix and displaying the size).

@Anthropos888
Copy link
Contributor Author

@david-allison-1 Interesting. I never realized that AnkiDroid silently compresses camera images. What is the threshold? I can insert pictures from camera that are 2.9MB without getting a notice.

And if the code is already there, why not make "resize and compress" as button available for all pictures? Sometimes I insert downloaded images >100kB which I find quite large. So I have to manually resize and compress those pictures with my photo app.

@mikehardy
Copy link
Member

@Anthropos888 it rotates and compresses no matter what - every image: 7c0811c#diff-6106bd1e14ca30faa16f8622fd8cf92eR186

First it loads into a 1920 max width bitmap (which will shrink some images just to start), then it attempts to compress as by converting to PNG. The problem is that the PNG compression is lossless and some things (like image data, frequently) doesn't compress well, so the clipping is useful but the compression may not work great.

There's a PR to allow AnkiDroid to store the inbound image you took (from camera or gallery) and then call the application configured on the system for cropping so users can really make a size difference by cutting images down, but it's not merged yet #5301

mikehardy pushed a commit that referenced this issue Mar 26, 2020
* Fix #5856 - Image Preview Crash

When loading an existing image, we performed the image load before we
had created all elements of the UI. This caused issues.

We fix this by splitting UI creation and initialisation logic

* Fix #5856 - Fix API Errors

createUI has `@SuppressLint("NewApi")` due to camera permissioning,
but it masked a bug in calling setBackground with lower API levels

* Added Unit Tests

Very basic right now, but there's a lot of value in ensuring that a
screen can be created with no errors.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants