Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@eggfly
Copy link
Member

@eggfly eggfly commented Aug 7, 2021

This PR fixes a Android crash when using WebView and when keyboard shows, flutter area was resized to a zero height.
Java crash stack:

E/AndroidRuntime(24165): Process: io.flutter.plugins.webviewflutterexample, PID: 24165
E/AndroidRuntime(24165): java.lang.IllegalArgumentException: The image dimensions must be positive
E/AndroidRuntime(24165): 	at android.media.ImageReader.<init>(ImageReader.java:247)
E/AndroidRuntime(24165): 	at android.media.ImageReader.newInstance(ImageReader.java:135)
E/AndroidRuntime(24165): 	at io.flutter.embedding.android.FlutterImageView.createImageReader(FlutterImageView.java:124)
E/AndroidRuntime(24165): 	at io.flutter.embedding.android.FlutterImageView.resizeIfNeeded(FlutterImageView.java:266)
E/AndroidRuntime(24165): 	at io.flutter.embedding.android.FlutterImageView.onSizeChanged(FlutterImageView.java:345)
E/AndroidRuntime(24165): 	at android.view.View.sizeChange(View.java:22113)
E/AndroidRuntime(24165): 	at android.view.View.setFrame(View.java:22065)
E/AndroidRuntime(24165): 	at android.view.View.layout(View.java:21924)
E/AndroidRuntime(24165): 	at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
E/AndroidRuntime(24165): 	at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
E/AndroidRuntime(24165): 	at android.view.View.layout(View.java:21927)
E/AndroidRuntime(24165): 	at android.view.ViewGroup.layout(ViewGroup.java:6260)
E/AndroidRuntime(24165): 	at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
E/AndroidRuntime(24165): 	at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
E/AndroidRuntime(24165): 	at android.view.View.layout(View.java:21927)
E/AndroidRuntime(24165): 	at android.view.ViewGroup.layout(ViewGroup.java:6260)
E/AndroidRuntime(24165): 	at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
E/AndroidRuntime(24165): 	at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
E/AndroidRuntime(24165): 	at android.view.View.layout(View.java:21927)
E/AndroidRuntime(24165): 	at android.view.ViewGroup.layout(ViewGroup.java:6260)
E/AndroidRuntime(24165): 	at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1829)
E/AndroidRuntime(24165): 	at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1673)
E/AndroidRuntime(24165): 	at android.widget.LinearLayout.onLayout(LinearLayout.java:1582)
E/AndroidRuntime(24165): 	at android.view.View.layout(View.java:21927)
E/AndroidRuntime(24165): 	at android.view.ViewGroup.layout(ViewGroup.java:6260)
E/AndroidRuntime(24165): 	at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
E/AndroidRuntime(24165): 	at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
E/AndroidRuntime(24165): 	at android.view.View.layout(View.java:21927)
E/AndroidRuntime(24165): 	at android.view.ViewGroup.layout(ViewGroup.java:6260)
E/AndroidRuntime(24165): 	at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1829)
E/AndroidRuntime(24165): 	at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1673)
E/AndroidRuntime(24165): 	at android.widget.LinearLayout.onLayout(LinearLayout.java:1582)
E/AndroidRuntime(24165): 	at android.view.View.layout(View.java:21927)
E/AndroidRuntime(24165): 	at android.view.ViewGroup.layout(ViewGroup.java:6260)
E/AndroidRuntime(24165): 	at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
E/AndroidRuntime(24165): 	at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
E/AndroidRuntime(24165): 	at com.android.internal.policy.DecorView.onLayout(DecorView.java:779)
E/AndroidRuntime(24165): 	at android.view.View.layout(View.java:21927)
E/AndroidRuntime(24165): 	at android.view.ViewGroup.layout(ViewGroup.java:6260)
E/AndroidRuntime(24165): 	at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:3080)
E/AndroidRuntime(24165): 	at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2590)
E/AndroidRuntime(24165): 	at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1721)
E/AndroidRuntime(24165): 	at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7598)
E/AndroidRuntime(24165): 	at android.view.Choreographer$CallbackRecord.run(Choreographer.java:966)
E/AndroidRuntime(24165): 	at android.view.Choreographer.doCallbacks(Choreographer.java:790)
E/AndroidRuntime(24165): 	at android.view.Choreographer.doFrame(Choreographer.java:725)
E/AndroidRuntime(24165): 	at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:951)
E/AndroidRuntime(24165): 	at android.os.Handler.handleCallback(Handler.java:883)
E/AndroidRuntime(24165): 	at android.os.Handler.dispatchMessage(Handler.java:100)
E/AndroidRuntime(24165): 	at android.os.Looper.loop(Looper.java:214)
E/AndroidRuntime(24165): 	at android.app.ActivityThread.main(ActivityThread.java:7356)
E/AndroidRuntime(24165): 	at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(24165): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
E/AndroidRuntime(24165): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
I/Process (24165): Sending signal. PID: 24165 SIG: 9

It fixed: flutter/flutter#87858

This is a workaround and stay the same with this logic of FlutterImageView's constructors, they take 1 pixel as default:

  /**
   * Constructs a {@code FlutterImageView} with an {@link android.media.ImageReader} that provides
   * the Flutter UI.
   */
  public FlutterImageView(@NonNull Context context, int width, int height, SurfaceKind kind) {
    this(context, createImageReader(width, height), kind);
  }

  public FlutterImageView(@NonNull Context context) {
    this(context, 1, 1, SurfaceKind.background);
  }

  public FlutterImageView(@NonNull Context context, @NonNull AttributeSet attrs) {
    this(context, 1, 1, SurfaceKind.background);
  }

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides].
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See [testing the engine] for instructions on
    writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the [CLA].
  • All existing and new tests are passing.

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@eggfly
Copy link
Member Author

eggfly commented Aug 7, 2021

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Test added. 😄

@jason-simmons
Copy link
Member

@blasten

@eggfly eggfly changed the title Avoid crash when FlutterImageView is resized to zero dimension Avoid crashing when FlutterImageView is resized to zero dimension Aug 9, 2021
Copy link

@blasten blasten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM % nit about the message

Copy link

@blasten blasten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@blasten blasten added the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Aug 10, 2021
@fluttergithubbot fluttergithubbot merged commit a1fd1e1 into flutter:master Aug 10, 2021
@eggfly eggfly deleted the master_avoid_resize_to_zero branch August 10, 2021 02:47
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla: yes needs tests platform-android waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Android app with webview_flutter crashes when FlutterImageView is resized to zero dimension

4 participants