Skip to content

[Web] A deep copy never occurs with "Path.from" #46813

@andymillernz

Description

@andymillernz

Path.copy creates a new Path object that is a "pointer" to the original. Any changes to either Path object is reflected across both.

I believe on IOS/Android a deep copy occurs when a change is made to either path object, however this doesn't happen with the WEB implementation.

There is a test program in engine/testing/dart/path_test.dart that should be catching this - I don't have an engine dev environment setup so unable to test this.

In the following test code paths p1 and p2 remain identical with a web build..

void main() {
  final Path p1 = Path()..lineTo(20.0, 20.0);
  final Path p2 = Path.from(p1);
  Rect r1 = p1.getBounds();
  Rect r2 = p2.getBounds();

  print('$r1 $r2');  // correctly display the same info 

  p1.lineTo(10.0, 30.0);
  r1 = p1.getBounds();
  r2 = p2.getBounds();
  print('$r1 $r2');   // shows that both paths bounds have changed 

  p2.lineTo(0.0, 3.0);
  p2.lineTo(1.0, 40.0);
  print('Path1: $p1 \nPath2: $p2');  // shows both paths as being the same
}

Problem does not happen when built for desktop, but does for chrome - and happens on both the dev and master channels

❯ flutter run -d macOS
flutter: Rect.fromLTRB(0.0, 0.0, 20.0, 20.0) Rect.fromLTRB(0.0, 0.0, 20.0, 20.0)
flutter: Rect.fromLTRB(0.0, 0.0, 20.0, 30.0) Rect.fromLTRB(0.0, 0.0, 20.0, 20.0)
flutter: Path1: Instance of 'Path'
Path2: Instance of 'Path'

❯ flutter run -d chrome
Rect.fromLTRB(0.0, 0.0, 20.0, 20.0) Rect.fromLTRB(0.0, 0.0, 20.0, 20.0)
Rect.fromLTRB(0.0, 0.0, 20.0, 30.0) Rect.fromLTRB(0.0, 0.0, 20.0, 30.0)
Path1: Path(Subpath(MoveTo(0, 0), LineTo(20, 20), LineTo(10, 30), LineTo(0, 3), LineTo(1, 40)))
Path2: Path(Subpath(MoveTo(0, 0), LineTo(20, 20), LineTo(10, 30), LineTo(0, 3), LineTo(1, 40)))

Output from flutter doctor -v

❯ flutter doctor -v
[✓] Flutter (Channel master, v1.13.1-pre.99, on Mac OS X 10.15.2 19C57, locale en-NZ)
    • Flutter version 1.13.1-pre.99 at /Users/andymiller/development/flutter
    • Framework revision 354f80b84a (20 hours ago), 2019-12-11 16:36:03 -0800
    • Engine revision 12bf95fd49
    • Dart version 2.7.0 (build 2.7.0-dev.2.1 8b8894648f)

[✗] Android toolchain - develop for Android devices
    ✗ Unable to locate Android SDK.
      Install Android Studio from: https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK components.
      (or visit https://flutter.dev/setup/#android-setup for detailed instructions).
      If the Android SDK has been installed to a custom location, set ANDROID_HOME to that location.
      You may also want to add it to your PATH environment variable.


[✓] Xcode - develop for iOS and macOS (Xcode 11.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.3, Build version 11C29
    • CocoaPods version 1.8.4

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[!] Android Studio (not installed)
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/setup/#android-setup for detailed instructions).

[✓] VS Code (version 1.40.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.7.1

[✓] Connected device (3 available)
    • macOS      • macOS      • darwin-x64     • Mac OS X 10.15.2 19C57
    • Chrome     • chrome     • web-javascript • Google Chrome 79.0.3945.79
    • Web Server • web-server • web-javascript • Flutter Tools

! Doctor found issues in 2 categories.

Metadata

Metadata

Assignees

Labels

c: renderingUI glitches reported at the engine/skia or impeller rendering levelengineflutter/engine related. See also e: labels.platform-webWeb applications specifically

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions