flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
164.94k stars 27.18k forks source link

NPE in Surface.createOrUpdateSurface #154402

Open kpsroka opened 2 weeks ago

kpsroka commented 2 weeks ago

Steps to reproduce

  1. Navigate to https://app.superlist.com/ (in Firefox, Chrome, or Edge)
  2. ???.
  3. Notice errors thrown in console. (no profit)

While I'm not sure how to consistently reproduce this, some Superlist users seem to do. It's hard to guess what's the actual impact on user experience as well, but our Sentry gets hammered with this. Given that these can happen repeatedly for a single client I'd assume that process actually doesn't crash.

Expected results

No crashes reported!

Actual results

Crashes are reported :(

Code sample

Sadly it's too deep in the bowels of engine to figure out user-side code.

Screenshots or Video

Stack trace The code lines don't match very well, but calls do. ``` minified:aIP: Null check operator used on a null value at Surface.createOrUpdateSurface(org-dartlang-sdk:///lib/_engine/engine/canvaskit/surface.dart:249:24) at OffscreenCanvasViewRasterizer.rasterizeToCanvas.a5X.prototypebaf(org-dartlang-sdk:///lib/_engine/engine/canvaskit/offscreen_canvas_rasterizer.dart:61:16) at ViewRasterizer.draw(org-dartlang-sdk:///lib/_engine/engine/canvaskit/rasterizer.dart:60:5) at _wrapJsFunctionForAsync(org-dartlang-sdk:///dart-sdk/lib/_internal/js_runtime/lib/async_patch.dart:303:19) at _wrapJsFunctionForAsync.(org-dartlang-sdk:///dart-sdk/lib/_internal/js_runtime/lib/async_patch.dart:328:23) at _asyncStartSync(org-dartlang-sdk:///dart-sdk/lib/_internal/js_runtime/lib/async_patch.dart:233:3) at ViewRasterizer.draw(org-dartlang-sdk:///lib/_engine/engine/canvaskit/rasterizer.dart:45:19) at ViewRasterizer.draw(org-dartlang-sdk:///lib/_engine/engine/canvaskit/rasterizer.dart:45:19) at CanvasKitRenderer._renderScene(org-dartlang-sdk:///lib/_engine/engine/canvaskit/renderer.dart:433:11) at _wrapJsFunctionForAsync(org-dartlang-sdk:///dart-sdk/lib/_internal/js_runtime/lib/async_patch.dart:303:19) ```
JS code snippet This is where the StackTrace points to from in the compiled JS code: ``` if(!g.d){s=g.cy if(s!=null&&d===s.a&&a.b===s.b){r=$.lg().d if(r==null){d=self.window.devicePixelRatio r=d===0?1:d}if(g.c&&r!==g.ay)g.Ks() d=g.a d.toString [<-- this line] ``` It corresponds very neatly with [web_ui/lib/src/engine/canvaskit/surface.dart](https://github.com/flutter/engine/blob/main/lib/web_ui/lib/src/engine/canvaskit/surface.dart#L254-L263)

Logs

No response

Flutter Doctor output

Doctor output ```console [!] Flutter (Channel master, 3.24.0-1.0.pre.565, on macOS 14.6.1 23G93 darwin-arm64, locale en-GB) • Flutter version 3.24.0-1.0.pre.565 on channel master at /Users/krzysztof/Workspace/superlist/.flutter ! Warning: `flutter` on your path resolves to /Users/krzysztof/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/krzysztof/Workspace/superlist/.flutter. Consider adding /Users/krzysztof/Workspace/superlist/.flutter/bin to the front of your path. ! Warning: `dart` on your path resolves to /Users/krzysztof/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/krzysztof/Workspace/superlist/.flutter. Consider adding /Users/krzysztof/Workspace/superlist/.flutter/bin to the front of your path. ! Upstream repository https://github.com/superlistapp/flutter.git is not a standard remote. Set environment variable "FLUTTER_GIT_URL" to https://github.com/superlistapp/flutter.git to dismiss this error. • Framework revision f2ba204917 (2 weeks ago), 2024-08-13 11:20:08 -0400 • Engine revision 77cd5447b9 • Dart version 3.6.0 (build 3.6.0-144.0.dev) • DevTools version 2.38.0 • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades. [✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0) • Android SDK at /Users/krzysztof/Library/Android/sdk • Platform android-35, build-tools 35.0.0 • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 15.4) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 15F31d • CocoaPods version 1.15.2 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2023.2) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874) [✓] VS Code (version 1.92.2) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.94.0 [✓] Connected device (4 available) • iPhone SE RED (mobile) • 00008110-001931D414E0401E • ios • iOS 17.3.1 21D61 • macOS (desktop) • macos • darwin-arm64 • macOS 14.6.1 23G93 darwin-arm64 • Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin • macOS 14.6.1 23G93 darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 128.0.6613.113 [✓] Network resources • All expected network resources are available. ! Doctor found issues in 1 category. ```
darshankawar commented 2 weeks ago

Thanks for the report and potential fix @kpsroka

  1. Navigate to https://app.superlist.com/ (in Firefox, Chrome, or Edge)

I accessed this link in Chrome, but didn't see any error log in the console, assuming the error probably is thrown in production mode.

Based on the report, crash log and potential fix, I will keep the issue open and label for team's tracking, although a minimal reproducible code sample would be helpful to properly analyze the reason of the crash.

kpsroka commented 2 weeks ago

@darshankawar Thanks for triage. As written in the description, this is deep inside the engine, and it's hard to have a reproduction (see Step 2 :) ).

However, I noticed that before this error, there's another one - MakeOnScreenGLSurface in JS code throws. It would explain the subsequent problems in Surface.createOrUpdateSurface. However, I believe fixing this one is still valuable - it prevents a whole range of problems because it makes internal state consistent.

kpsroka commented 2 weeks ago

Did a little bit more digging. MakeOnScreenGLSurface throws on the following line: https://github.com/google/skia/blob/f3811180e7df510f157228a17805f1c12cdf9e52/modules/canvaskit/cpu.js#L12

The messages depend on browser, but essentially they are "right hand side operand of 'instanceof' is not an object".

That means that somewhere in the JS-land OffscreenCanvas is either ill-defined, or overwritten.

kpsroka commented 6 days ago

Did a little bit more digging. MakeOnScreenGLSurface throws on the following line: https://github.com/google/skia/blob/f3811180e7df510f157228a17805f1c12cdf9e52/modules/canvaskit/cpu.js#L12

Obviously, I mixed it all up and it's MakeSWCanvasSurface that throws.