From a5c60f412834d4c0ce67c0fb74f70107504c9777 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rulong=20Chen=EF=BC=88=E9=99=88=E6=B1=9D=E9=BE=99=EF=BC=89?= <26625149+0xZOne@users.noreply.github.com> Date: Mon, 27 Feb 2023 22:52:40 +0800 Subject: [PATCH] Limit the PlatformView ID within the range of 32-bit integers. (#121203) Limit the PlatformView ID within the range of 32-bit integers. --- packages/flutter/lib/src/services/platform_views.dart | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/services/platform_views.dart b/packages/flutter/lib/src/services/platform_views.dart index d2feeb8603..9dab5b1042 100644 --- a/packages/flutter/lib/src/services/platform_views.dart +++ b/packages/flutter/lib/src/services/platform_views.dart @@ -44,7 +44,16 @@ class PlatformViewsRegistry { /// /// Typically a platform view identifier is passed to a platform view widget /// which creates the platform view and manages its lifecycle. - int getNextPlatformViewId() => _nextPlatformViewId++; + int getNextPlatformViewId() { + // On the Android side, the interface exposed to users uses 32-bit integers. + // See https://github.com/flutter/engine/pull/39476 for more details. + + // We can safely assume that a Flutter application will not require more + // than MAX_INT32 platform views during its lifetime. + const int MAX_INT32 = 0x7FFFFFFF; + assert(_nextPlatformViewId <= MAX_INT32); + return _nextPlatformViewId++; + } } /// Callback signature for when a platform view was created.