flutter-unity-view-widget icon indicating copy to clipboard operation
flutter-unity-view-widget copied to clipboard

Flutter 3.19 breaks Unitywidget on Android 12+ screen transition, resize, screen rotation or keyboard open.

Open timbotimbo opened this issue 1 year ago • 6 comments

Description

Just a warning about using Flutter 3.19 on Android 12+. The Unitywidget will break when a keyboard is openend or the screen is rotated.

It will end up spamming the following error:

E/BufferQueueProducer(17453): [ImageReader-1080x2000f22m4-17453-17](id:442d0000001b,api:1,p:1104,c:17453) dequeueBuffer: BufferQueue has been abandoned

You can only recover from this by fully removing the UnityWidget from the widget tree.

This does not happen on Android 11 and lower.

The Flutter 3.20 beta and master channel fix this bug, but that introduces another Unity bug.
Flutter now resizes the platform view and Unity can't seem to handle that. It will resize to the wrong size.

Workarounds

[UPDATE] Flutter 3.22 fixes the issue and can be used without workaround.

You've got 4 choices for now:

  • use Flutter up to 3.13.9
  • Use Flutter Up to 3.16.9 (with bug on Android < 8)
  • use useAndroidViewSurface: true
  • use 3.20 beta and don't use rotation or keyboard

Video

The red color is a container behind the unitywidget, to show when it is transparent or invisible.
The 3.19 videos were recorded on an earlier beta, but you get the same visual result on 3.19 stable.

S20FE Keyboard open videos

1: 3.162: 3.193: master (3.20)

https://github.com/flutter/flutter/assets/11444698/05c30381-bfb0-49af-8122-d41d90de7746

https://github.com/flutter/flutter/assets/11444698/0abf4cbb-ca08-4a3c-9334-4c99dc035763

https://github.com/flutter/flutter/assets/11444698/92652386-80ad-4db6-89b1-d22f49cb25e3

Screen rotation videos

4: 3.165: 3.196: master (3.20)

https://github.com/flutter/flutter/assets/11444698/5fa5b83b-5ce3-4aa2-ae9d-8516b76ae70f

https://github.com/flutter/flutter/assets/11444698/7e88f1fa-6744-4672-8bb9-bfb4fbd42229

https://github.com/flutter/flutter/assets/11444698/c9977f33-eaf8-4f34-8129-210a0ae40e8b

Versions

  • Unity: This applies to all Unity versions
  • Flutter: 3.19 stable
  • Android: Android 12 and up.

timbotimbo avatar Feb 19 '24 08:02 timbotimbo

Is the third workaround "use useAndroidViewSurface: true" really a workaround?

According to this issue (and two more related ones) this mode introduces more issues than working around, right?

  • https://github.com/juicycleff/flutter-unity-view-widget/issues/766

As of now, what is the best setup for using Flutter with Unity and the widget and avoid rendering or touch input issues? Probably Flutter 3.13.9 + Unity with old input system ?

hdeppert avatar Feb 20 '24 07:02 hdeppert

[UPDATE] the upsides list below is outdated as of Flutter 3.22, in which the visibility and rotation issues are fixed when using useAndroidViewSurface: false.

Regarding useAndroidViewSurface.

Downsides:

  • Push/pop transitions look bad (flutter issue)
  • Issues with Flutter effects like blur or clipping.
  • Possible worse performance
  • Invisible on Android 6 & 7
  • In specific use cases it can pop over flutter on app resume (flutter issue)

Upsides:

  • New input system
  • Screen rotations and keyboard are smooth and not broken.
  • Doesn't have a chance to randomly turn invisible on resume or rotation.
  • Visible on Android 8 on Flutter >= 3.16

With these new issues popping up, the downsides are getting more and more acceptable.

I still prefer to stick with <= 3.13.9.
But my app does contain text instructions behind the UnityWidget on how to reset it, in case it turns invisible.

timbotimbo avatar Feb 20 '24 09:02 timbotimbo

Glad I found this.. I was trying to work out why unity wasn't working at all on android 12+. Not just on resize - at all.. Downgrading flutter just not an option for us, we have functionality that relies on 3.19

Setting useAndroidViewSurface true fixed it and as far as I can see we haven't hit any downsides, it works just the same as before.

TonyHoyle avatar Feb 22 '24 13:02 TonyHoyle

Fixes for this are included in Flutter 3.22

timbotimbo avatar May 14 '24 08:05 timbotimbo

Fixes for this are included in Flutter 3.22

Thanks for the update! Do you have any update regarding your previous comment and recommendation on which version/setup should be used with which up-/downsides?

hdeppert avatar May 16 '24 18:05 hdeppert

@hdeppert Flutter is actively trying to move away from Hybrid Composition (useAndroidViewSurface: true), and only keeping it around for some edge cases. I would recommend avoiding it unless you actually run into a bug that actually needs it.

Most upsides listed above are now negated in flutter 3.22. Screen rotations, resizes and visibility issues all seem to be fixed. Although the resize doesn't look as smooth as when using Hybrid composition.

Handling touch with the new input system is now the main difference, but it can be made to work in Virtual display too https://github.com/juicycleff/flutter-unity-view-widget/pull/938.

timbotimbo avatar Jun 07 '24 09:06 timbotimbo