Skip to content

[Android] Virtual display - Buggy resize with Android 12+ #142952

@timbotimbo

Description

@timbotimbo

Description

A Unity widget shown in a Virtual Dispay platform view, will not properly resize on Flutter versions > 3.16.x.
This resize can be triggered by things like changing the parent size, opening the keyboard or the screen rotating to landscape.

  • The beta channel introduces a commit that breaks the widget on resize.
  • The master channel introduces a commit that fixes the error breaking the widget, but results in a wrong widget size.

1 - Current (Flutter 3.3-> 3.16)

(see video 1 and 4)
On a keyboard or screen rotation, the widget resizes to the correct size, with some visual flashes caused by Unity.

On Android 12+, in some cases (5%?) the widget will become invisible after a resize, with the log spamming: dequeueBuffer: BufferQueue has no connected producer.

2 - Beta (e.g 3.19.0-0.4.pre)

(see video 2 and 5)
This PR flutter/engine#47946 introduces a resize function for android 12+.
This commit causes the Unity widget to freeze on resize, and spam the console with:

I/ImageReaderSurfaceProducer(20245): Skipped frame because resize is in flight.
I/ImageReaderSurfaceProducer(20245): Skipped frame because resize is in flight.
I/ImageReaderSurfaceProducer(20245): Skipped frame because resize is in flight.

The widget does not recover from this freeze until you remove it from the tree and recreate it.

Either Unity or the Unity plugins cannot hande this resize. Maybe handling this in the plugin would be an easy solution, but how?

3 - Master (e.g 3.20.0-0.0.pre)

(see video 3, 6,7 and 8)
The commit including this PR flutter/engine#50155, changes the results from beta.
The 'resize in flight' error is gone and the widget no longer freezes.
However the widget becomes the wrong size after a resize. (see the landscape video to see it only become 50% height)

This change does not do anything on Android <12, which makes me think this is still caused by flutter/engine#47946 and only the bug symptoms have changed because of other changes.

Code sample

I've got 2 reproduction projects that are nearly identical, only changing the Unity plugin.

  1. uses flutter_embed_unity (used for the logs and videos below)
    https://github.com/timbotimbo/flutter_fuw_reproduction_android/tree/flutter_embed_unity_textfield
  2. uses flutter_unity_widget
    https://github.com/timbotimbo/flutter_fuw_reproduction_android/tree/main_textfield

The first plugin is a newer and cleaner implementation, the second is more popular with more users.
The plugin choice doesn't matter for reproduction but might be useful if you wan't to check or compare something.

Steps to reproduce

I recommend to reproduce this on a real Android device.

Unity doesn't officially support (x86/x64) emulators and you might get unexpected results.
My emulator success depends on CPU type:

  • On Apple Silicon, the ARM64 emulator works as expected.
    Only the bug mentioned for 3.16 occurs much more often. (timeout or race condition?)
  • On an Intel CPU, the x64 emulator shows Unity as expected, but sometimes crashes randomly.
  • On an AMD Ryzen CPU, the x64 emulator only shows a purple screen.
    You can still see the symptoms of the issue as the purple screen resizes to the wrong size on master. (see the last video)

Steps:

  1. Download or clone the branch linked under code sample
  2. Run the flutter application on Android.
  3. Click the 'Toggle' button to make Unity show up.
  4. Click the textfield or rotate your device to trigger a resize.
  5. On Android < 12, this is the same on Flutter 3.16, 3.19 beta and master (3.20).
  6. On Android >=12 the issues show up on beta 3.19 and master.

Expected result

The platform view should resize just like on flutter <= 3.16 when on Android >= 12.
The platform view should resisze just like on Android < 12, which isn't broken.

I'm not sure if this should be fixed in Flutter or if there are event or functions that can allow the Unity plugins to handle the new resize31 function.

Actual result

On 3.19 beta versions the platform view freezes with an error in the console.
On master the platform view resizes to the wrong size.

Video

The red color is a container behind the unitywidget, to show when it is transparent or invisible.

All 3 variantions on Android 13, Samsung Galaxy S20FE.

S20FE Keyboard open videos

1: 3.162: 3.193: master (3.20)
S20FE_3.16_keyboard.mp4
S20FE_3.19_keyboard.mp4
S20FE_master_keyboard.mp4

(expandable) S20FE screen rotation videos
4: 3.165: 3.196: master (3.20)
S20FE_3.16_rotate.mp4
S20FE_3.19_rotate.mp4
S20FE_master_rotate.mp4
(expandable) Master channel on x64 Pixel emulators
7: Intel8: AMD
intel_x64_pixel_master.mp4
amd_x64_pixel_master2.mp4

Devices

I can receate this on a real device and various emulators:

  • Samsung Galaxy S20FE, Android 13
  • Pixel 4a emulator ARM64, API33
  • Pixel XL emulator ARM64, API34
  • Pixel 4 emulator x64, API33

Devices and emulators < android 12 (API31) can not reproduce this.

Logs

These logs are the debug console when I do the following:

  • Touch the textfield while Unity is running
  • Hit back button once keyboard is open
  • Terminate debug session

Logs added as text files because of character limits.

Flutter 3.16.9 (normal)
3.16.txt

Flutter 3.19.0-0.4-pre-beta (resize in flight)
3.19.txt

Flutter master (wrong size)
master.txt

Flutter Doctor output

flutter doctor on windows & master

[√] Flutter (Channel master, 3.20.0-2.0.pre.9, on Microsoft Windows [Version 10.0.19045.3930], locale en-NL)
    • Flutter version 3.20.0-2.0.pre.9 on channel master at C:\src\flutter-master
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 809a27ea67 (4 hours ago), 2024-02-05 11:29:22 -0600     
    • Engine revision f34c658b96
    • Dart version 3.4.0 (build 3.4.0-99.0.dev)
    • DevTools version 2.31.0

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at C:\Users\XXXXXX\AppData\Local\Android\sdk
    • Platform android-33, build-tools 33.0.0
    • Java binary at: C:\Program Files\Android\Android Studio2\jbr\bin\java      
    • Java version OpenJDK RunXXXXXXe Environment (build 17.0.6+0-b2043.56-10027231)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Community 2019 16.11.21)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
    • Visual Studio Community 2019 version 16.11.33027.164
    • Windows 10 SDK version 10.0.18362.0

[!] Android Studio (version 2022.2)
    • Android Studio at C:\Program Files\Android\Android Studio1
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    X Unable to determine bundled Java version.
    • Try updating or re-installing Android Studio.

[√] Android Studio (version 2022.3)
    • Android Studio at C:\Program Files\Android\Android Studio2
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK RunXXXXXXe Environment (build 17.0.6+0-b2043.56-10027231)

[√] VS Code (version 1.86.0)
    • VS Code at C:\Users\XXXXXX\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.82.0

[√] Connected device (5 available)
    • SM G780G (mobile)            • RF8R8021WSR   • android-arm64  • Android 13 (API 33)
    • sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64    • Android 13 (API 33) (emulator)
    • Windows (desktop)            • windows       • windows-x64    • Microsoft Windows [Version 10.0.19045.3930]
    • Chrome (web)                 • chrome        • web-javascript • Google Chrome 121.0.6167.140
    • Edge (web)                   • edge          • web-javascript • Microsoft Edge 121.0.2277.98

[√] Network resources
    • All expected network resources are available.

! Doctor found issues in 1 category.

Other

Because both mentioned pull requests were either authored or reviewd by you, I'm tagging @johnmccutchan.
Let me know if this is unwanted and too direct.

Metadata

Metadata

Assignees

Labels

c: regressionIt was better in the past than it is nowe: OS-version specificAffects only some versions of the relevant operating systemfound in release: 3.19Found to occur in 3.19found in release: 3.20Found to occur in 3.20has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-androidAndroid applications specificallyplatform-views: vdIssues specific to the Android VirtualDisplay platform views backendteam-androidOwned by Android platform team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions