Steps to reproduce
This crash was found via Sentry on a production Flutter web app (CanvasKit renderer, release mode). It has occurred 8 times across users but AFAIK seamless for users.
No manual repro steps — it appears to be a race condition triggered by browser GPU pressure or specific browser environments.
Expected results
No crash. The webglcontextlost event should be handled safely even if it fires before CkSurface constructor completes.
Actual results
LateInitializationError: Field '' has not been initialized.
(Field name is empty due to dart2js --omit-late-names in release mode.)
Stack trace (deobfuscated via source maps)
at throwUnnamedLateFieldNI (dart-sdk/lib/_internal/js_runtime/lib/late_helper.dart:31:3)
at CkSurface.get _canvas (lib/_engine/engine/canvaskit/surface.dart:81:25)
at CanvasProvider.acquireCanvas (lib/_engine/engine/compositing/canvas_provider.dart:24:7)
triggered from: OffscreenCanvas webglcontextlost event handler
Root cause analysis
In canvas_provider.dart, acquireCanvas() registers a webglcontextlost event listener on the canvas before returning it. In CkSurface's constructor, _canvas (a late field) is assigned from the return value of acquireCanvas():
_canvas = _canvasProvider.acquireCanvas(_currentSize, onContextLost: onContextLost);
If the webglcontextlost event fires synchronously or near-synchronously during canvas creation, onContextLost() is invoked while _canvas is still uninitialized, causing the LateInitializationError.
Environment
- Flutter: 3.41.2 (stable)
- Renderer: CanvasKit (web)
- Build mode: Release (
--release --source-maps)
- Sentry SDK: sentry.javascript.browser.flutter 10.38.0
- Observed browsers: Could not determine (Sentry event lacked browser tags)
Notes
This bug was elicited by AI analysis and found on Sentry in production. There is no visible impact on users AFAIK.
Steps to reproduce
This crash was found via Sentry on a production Flutter web app (CanvasKit renderer, release mode). It has occurred 8 times across users but AFAIK seamless for users.
No manual repro steps — it appears to be a race condition triggered by browser GPU pressure or specific browser environments.
Expected results
No crash. The
webglcontextlostevent should be handled safely even if it fires beforeCkSurfaceconstructor completes.Actual results
(Field name is empty due to dart2js
--omit-late-namesin release mode.)Stack trace (deobfuscated via source maps)
Root cause analysis
In
canvas_provider.dart,acquireCanvas()registers awebglcontextlostevent listener on the canvas before returning it. InCkSurface's constructor,_canvas(alatefield) is assigned from the return value ofacquireCanvas():If the
webglcontextlostevent fires synchronously or near-synchronously during canvas creation,onContextLost()is invoked while_canvasis still uninitialized, causing theLateInitializationError.Environment
--release --source-maps)Notes
This bug was elicited by AI analysis and found on Sentry in production. There is no visible impact on users AFAIK.