Skip to content

Commit

Permalink
Limit the PlatformView ID within the range of 32-bit integers. (#121203)
Browse files Browse the repository at this point in the history
Limit the PlatformView ID within the range of 32-bit integers.
  • Loading branch information
0xZOne authored Feb 27, 2023
1 parent fbae472 commit a5c60f4
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/flutter/lib/src/services/platform_views.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit a5c60f4

Please sign in to comment.