Skip to content

3.24.x introduced a regression in Golden Tests using a widget with a matrix perspective transform #155450

Closed
flutter-team-archive/engine
#55536

Description

@FufferKS

I'm using matrix transform to achieve a perspective view in my app. I'm also using golden tests heavily.
Upon migrating from 3.22.3 to 3.24.3, some of my goldens do not render the widgets properly anymore. The widgets render fine in the app.
One example uses an svg(I stripped this one down and attached as a code sample).
I also have issues with a png, so I don't think its svg specific.

I'm tagging @Hixie, since I've seen a couple of mentions to golden changes in release notes of 3.24, so I'm hoping you might know something.

Steps to reproduce

  • in pubspec.yaml add:
flutter:
  uses-material-design: true
  assets:
    - assets/icons/
  • in pubspec.yaml add:
    flutter_svg: ^1.1.6 dependency

  • add the svg under /assets/icons as ic_pound_sign.svg
    ic_pound_sign
    source:

<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M5 10.4628V12.6087H7.84923C7.86115 12.7279 7.86115 12.8471 7.86115 12.9663C7.86115 14.9215 6.88359 16.1613 5.19074 16.4355V20H18.7454V16.0898H11.1396V15.9467C12.2244 15.2314 12.5582 13.9439 12.5582 12.7518C12.5582 12.7041 12.5582 12.6564 12.5582 12.6087H17.3506V10.4628H12.1648C12.0337 9.96213 11.9144 9.49719 11.9144 9.03226C11.9144 7.64937 12.892 6.7195 15.014 6.7195C16.2539 6.7195 17.3029 6.91024 18.0659 7.24404V3.64376C17.446 3.28612 15.7532 3 14.108 3C9.60168 3 7.07433 5.16971 7.07433 8.12623C7.07433 8.92496 7.25316 9.69986 7.4439 10.4628H5Z" fill="white"/>
</svg>

  • Add a test with the attached code sample, run it with flutter test --update-goldens

Code sample

Code sample
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:flutter_test/flutter_test.dart';

Future<void> main() async {
  group('Flutter Perspective in goldens regression', () {
    for (final usePerspective in [false, true]) {
      testWidgets(
        'Simple widget ${usePerspective ? 'under' : 'without'} perspective',
        (widgetTester) async {
          const topLevelKey = Key('top level key');
          await widgetTester.pumpWidget(
            Center(
              child: Container(
                key: topLevelKey,
                color: Colors.red,
                height: 50,
                width: 50,
                child: Transform(
                  transform: Matrix4.identity()
                    ..setEntry(3, 1, usePerspective ? 0.015 : 0),
                  alignment: Alignment.bottomCenter,
                  child: Container(
                    alignment: Alignment.bottomCenter,
                    child: SvgPicture.asset('assets/icons/ic_pound_sign.svg'),
                  ),
                ),
              ),
            ),
          );
          await widgetTester.pump();
          await expectLater(
            find.byKey(topLevelKey),
            matchesGoldenFile(
              'goldens/simple_widget_${usePerspective ? 'under' : 'without'}_perspective.png',
            ),
          );
        },
      );
    }
  });
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]
3.22.3:

simple_widget_under_perspective_3_22
simple_widget_without_perspective_3_22

3.24.3:

simple_widget_under_perspective_3_24
simple_widget_without_perspective_3_24

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output

3.24:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.24.3, on macOS 14.5 23F79 darwin-arm64, locale en-PL)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
[✓] Xcode - develop for iOS and macOS (Xcode 16.0)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.3)
[✓] IntelliJ IDEA Community Edition (version 2023.2.1)
[✓] VS Code (version 1.93.1)
[✓] Connected device (4 available)            
[✓] Network resources

• No issues found!

3.22:

[16](https://moneysatnav.slack.com/archives/D03C7D43F4N/p1726830992665529)
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.22.3, on macOS 14.6.1 23G93 darwin-arm64 (Rosetta), locale en-BG)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2023.1)
[✓] VS Code (version 1.93.1)
[✓] Connected device (5 available)
[✓] Network resources
• No issues found!

Activity

  1. danagbemava-nc commented on Sep 20, 2024

    @danagbemava-nc
    Member

    Reproducible using the code sample and steps outlined above.

    flutter doctor -v
    [✓] Flutter (Channel stable, 3.24.3, on macOS 15.0 24A335 darwin-arm64, locale en-US)
        • Flutter version 3.24.3 on channel stable at /Users/deanli/dev/stable
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 2663184aa7 (9 days ago), 2024-09-11 16:27:48 -0500
        • Engine revision 36335019a8
        • Dart version 3.5.3
        • DevTools version 2.37.3
    
    [!] Flutter (Channel master, 3.26.0-1.0.pre.167, on macOS 15.0 24A335 darwin-arm64, locale en-US)
        • Flutter version 3.26.0-1.0.pre.167 on channel master at /Users/deanli/dev/master
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 1095351700 (10 hours ago), 2024-09-19 23:50:24 -0400
        • Engine revision f5310c2345
        • Dart version 3.6.0 (build 3.6.0-268.0.dev)
        • DevTools version 2.40.0-dev.1
    
    
  2. added
    a: tests"flutter test", flutter_test, or one of our tests
    c: regressionIt was better in the past than it is now
    frameworkflutter/packages/flutter repository. See also f: labels.
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    and removed
    in triagePresently being triaged by the triage team
    on Sep 20, 2024
  3. Piinks commented on Sep 25, 2024

    @Piinks
    Contributor

    @FufferKS can you remove the dependency on package:flutter_svg/svg.dart? The issue may be in that package rather than the flutter framework.

  4. added
    in triagePresently being triaged by the triage team
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Sep 25, 2024
  5. FufferKS commented on Sep 26, 2024

    @FufferKS
    ContributorAuthor

    I'll do my best to prepare a repro without it tomorrow.
    However, my repro had the failures on the exact same version of flutter_svg on both flutter versions (checked in pubspec.lock) and on my app I'm experiencing the same perspective issue on a png asset, so I highly doubt it's svg's fault.

  6. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Sep 26, 2024
  7. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Sep 26, 2024
  8. jason-simmons commented on Sep 29, 2024

    @jason-simmons
    Contributor

    This started with the change to using Impeller geometry classes in DisplayListMatrixClipTracker (flutter-team-archive/engine@0226114)

    The difference happens because impeller::Matrix::Translate does not match the behavior of Skia's SkM44::preTranslate for the perspective matrix used in this example. Specifically, impeller::Matrix::Translate is copying m[15] into the output instead of multiplying against the translation vector.

    This renders as expected if I change Matrix::Translate to:

      constexpr Matrix Translate(const Vector3& t) const {
        return Matrix(m[0], m[1], m[2], m[3],
                      m[4], m[5], m[6], m[7],
                      m[8], m[9], m[10], m[11],
                      m[0] * t.x + m[4] * t.y + m[8]  * t.z + m[12],
                      m[1] * t.x + m[5] * t.y + m[9]  * t.z + m[13],
                      m[2] * t.x + m[6] * t.y + m[10] * t.z + m[14],
                      m[3] * t.x + m[7] * t.y + m[11] * t.z + m[15]);
      }
    

    @chinmaygarde @flar

  9. FufferKS commented on Sep 30, 2024

    @FufferKS
    ContributorAuthor

    Sorry for the delay, here is a repro with no svg.

    3.24:
    under perspective:
    simple_widget_under_perspective_png_3_24_3
    3.24:
    without perspective:
    simple_widget_without_perspective_png_3_24_3

    3.22:
    under perspective:
    simple_widget_under_perspective_png_3_22_3
    3.22:
    without perspective:
    simple_widget_without_perspective_png_3_22_3

    import 'package:flutter/material.dart';
    import 'package:flutter_test/flutter_test.dart';
    
    Future<void> main() async {
      group('Flutter Perspective in goldens regression', () {
        for (final usePerspective in [false, true]) {
          testWidgets(
            'Simple widget ${usePerspective ? 'under' : 'without'} perspective',
            (widgetTester) async {
              const topLevelKey = Key('top level key');
              await widgetTester.pumpWidget(
                Directionality(
                  textDirection: TextDirection.ltr,
                  key: topLevelKey,
                  child: Center(
                    child: Container(
                      color: Colors.red,
                      height: 500,
                      width: 50,
                      child: Transform(
                        transform: Matrix4.identity()
                          ..setEntry(3, 1, usePerspective ? 0.015 : 0),
                        alignment: Alignment.bottomCenter,
                        child: const ExampleList(),
                      ),
                    ),
                  ),
                ),
              );
              await widgetTester.pump();
              await expectLater(
                find.byKey(topLevelKey),
                matchesGoldenFile(
                  'goldens/simple_widget_${usePerspective ? 'under' : 'without'}_perspective_png_3_24_3.png',
                ),
              );
            },
          );
        }
      });
    }
    
    class ExampleList extends StatelessWidget {
      const ExampleList({super.key});
    
      @override
      Widget build(BuildContext context) {
        return ListView.builder(
          itemBuilder: (context, index) => const ExampleItem(),
        );
      }
    }
    
    class ExampleItem extends StatelessWidget {
      const ExampleItem({super.key});
    
      @override
      Widget build(BuildContext context) {
        return Center(
          child: Container(
            height: 80,
            width: 80,
            decoration: const BoxDecoration(color: Colors.blue),
          ),
        );
      }
    }
    
    
  10. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Sep 30, 2024
  11. FufferKS commented on Sep 30, 2024

    @FufferKS
    ContributorAuthor

    Regarding the comment from @jason-simmons, I should have mentioned that our app currently opts out of Impeller due to

    #153221
    #128885
    #149165

    Does it mean that between 3.22 and 3.24 the goldens started using the Impeller engine? My knowledge ends here, I am not sure if this question even makes sense.

  12. FufferKS commented on Sep 30, 2024

    @FufferKS
    ContributorAuthor

    Sorry it's also worth mentioning, that in the List/Item example a single Item renders fine, only wrapping it in the list starts to misbehave.

  13. added
    r: fixedIssue is closed as already fixed in a newer version
    on Oct 4, 2024
  14. github-actions commented on Oct 18, 2024

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  15. locked as resolved and limited conversation to collaborators on Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    a: tests"flutter test", flutter_test, or one of our testsc: regressionIt was better in the past than it is nowfound in release: 3.24Found to occur in 3.24found in release: 3.26Found to occur in 3.26frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versionteam-frameworkOwned by Framework team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions