Repository navigation
Description
Steps to reproduce
flutter create --platforms=windows angle_race_repro- Replace
lib/main.dartandwindows/runner/main.cppwith the code below. Add a publiccontroller()accessor toFlutterWindowinflutter_window.h. - Run
flutter build windows --releaseon 3.50.1, then runangle_race_repro.exe --trigger=frames --every=30 --count=20.
The main window animates a texture-heavy CustomPainter. From frame 120, on every 30th frame the runner opens a new top-level window with its own FlutterViewController; this is the same pattern desktop_multi_window uses. Engines are never destroyed, and the process exits with code 0 after creating 20.
Expected results
All 20 windows open, as they do on 3.47.9.
Actual results
An access violation (0xC0000005) in flutter_windows.dll, usually within a few seconds. Crashes per 20 runs, Windows 11, identical source:
| 3.50.1 | 3.47.9 | |
|---|---|---|
--trigger=frames, Intel UHD 770 |
20/20 | 0/20 |
--trigger=timer --interval=500, Intel UHD 770 |
18/20 | 0/20 |
--trigger=timer --interval=500, NVIDIA T1000 |
18/20 (plus 2 hangs) | 0/20 |
We hit this in production when users opened a second window, and the production crash sites recur in this sample.
The faulting thread is a raster thread mid-draw, for example:
Rasterizer::DrawToSurfaces → ReactorGLES::FlushOps → GL_DrawElements
→ StateManager11::updateState → applyTexturesForSRVs
→ ProgramExecutableD3D::getUsedImageRange // this == nullptr
The other sites are in the same code: syncUniformBuffersForShader, and applyIndexBuffer → VertexArray11::updateCachedIndexInfo. Each is a near-null access through StateManager11::mExecutableD3D or mVertexArray11. At the moment of the crash the new engine is in one of two places:
- in the
EmbedderSurfaceGLImpellerconstructor on the platform thread, just after its make-current; - in its first
CompositorOpenGL::Present.
Likely cause
All engines in a process share one EGLDisplay (egl/manager.cc, EGL_DEFAULT_DISPLAY), so they share one ANGLE StateManager11.
- In the ANGLE that 3.50 pins (
a8d74ca3),EGL_MakeCurrenttakes only the per-display lock, while GL calls take the global mutex. - In 3.47.9's ANGLE (
84027aca),EGL_MakeCurrenttook the global lock.
StateManager11::onMakeCurrent nulls mExecutableD3D and mVertexArray11, so one engine's make-current can race another engine's draw.
This looks related to #196618 and #197238, but it is a cross-engine path. #196897 serialises D3D11 context calls, not these ANGLE-side stores, so I'm not sure the planned fix covers it. Giving each engine its own EGL display might work as an embedder-side mitigation; max_feature_level already does this via EGL_PLATFORM_ANGLE_DISPLAY_KEY_ANGLE.
Our workaround is building the Windows target with 3.47.9.
Code sample
lib/main.dart
// Main window: continuous texture/sampler-heavy Impeller drawing.
// Secondary engines (created by the C++ runner) run a trivial UI.
import 'dart:math' as math;
import 'dart:typed_data';
import 'dart:ui' as ui;
import 'package:flutter/scheduler.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
int _flag(List<String> args, String name, int fallback) {
for (final a in args) {
if (a.startsWith('--$name=')) return int.parse(a.substring(name.length + 3));
}
return fallback;
}
void main(List<String> args) {
WidgetsFlutterBinding.ensureInitialized();
if (args.isNotEmpty && args.first == 'secondary') {
runApp(Directionality(
textDirection: TextDirection.ltr,
child: ColoredBox(
color: const Color(0xFF203040),
child: Center(child: Text('engine ${args[1]}', style: const TextStyle(fontSize: 32))),
),
));
return;
}
final work = _flag(args, 'work', 1);
final every = _flag(args, 'every', 30);
final burst = _flag(args, 'burst', 1);
var frames = 0;
// Runs after the frame's scene is handed to the raster thread; the runner
// may create a new engine while this frame is being drawn.
SchedulerBinding.instance.addPersistentFrameCallback((_) {
frames++;
final msg = ByteData(8)..setInt64(0, frames, Endian.little);
ServicesBinding.instance.defaultBinaryMessenger.send('repro/frames', msg);
});
runApp(HeavyApp(work: work, every: every, burst: burst, frameCount: () => frames));
}
class HeavyApp extends StatefulWidget {
const HeavyApp({super.key, required this.work, required this.every, required this.burst, required this.frameCount});
final int work, every, burst;
final int Function() frameCount;
@override
State<HeavyApp> createState() => _HeavyAppState();
}
class _HeavyAppState extends State<HeavyApp> with SingleTickerProviderStateMixin {
late final AnimationController _c = AnimationController(vsync: this, duration: const Duration(seconds: 2))..repeat();
late final ui.Image _img = _makeImage();
ui.Image _makeImage() {
final rec = ui.PictureRecorder();
final c = Canvas(rec);
for (var i = 0; i < 16; i++) {
final o = Offset(16.0 * i, 16.0 * (i % 4) * 4);
c.drawCircle(o, 60, Paint()..shader = ui.Gradient.radial(o, 60, [Color(0xFF000000 | (i * 0x0F1F2F)), const Color(0x0000FF00)]));
}
return rec.endRecording().toImageSync(256, 256);
}
@override
Widget build(BuildContext context) {
return AnimatedBuilder(
animation: _c,
builder: (_, _) {
final next = widget.frameCount() + 1;
final w = next % widget.every == 0 ? widget.work * widget.burst : widget.work;
return ImageFiltered(
imageFilter: ui.ImageFilter.blur(sigmaX: 1 + 2 * _c.value, sigmaY: 1 + 2 * _c.value),
child: CustomPaint(size: Size.infinite, painter: HeavyPainter(_c.value, _img, w, next)),
);
},
);
}
@override
void dispose() {
_c.dispose();
super.dispose();
}
}
class HeavyPainter extends CustomPainter {
HeavyPainter(this.t, this.img, this.work, this.frame);
final double t;
final ui.Image img;
final int work, frame;
@override
void paint(Canvas c, Size s) {
final r = math.Random(7);
final a = t * 2 * math.pi;
final src = Rect.fromLTWH(0, 0, img.width.toDouble(), img.height.toDouble());
final imgPaint = Paint()..filterQuality = FilterQuality.medium;
final m = Float64List.fromList([math.cos(a), math.sin(a), 0, 0, -math.sin(a), math.cos(a), 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
final shaderPaint = Paint()..shader = ImageShader(img, TileMode.repeated, TileMode.mirror, m);
final xforms = <RSTransform>[], rects = <Rect>[];
for (var k = 0; k < work; k++) {
for (var i = 0; i < 40; i++) {
final p = Offset(r.nextDouble() * s.width, r.nextDouble() * s.height);
final path = Path()
..moveTo(p.dx, p.dy)
..quadraticBezierTo(p.dx + 80 * math.cos(a + i), p.dy - 60, p.dx + 120, p.dy + 40 * math.sin(a))
..close();
c.drawPath(path, Paint()..shader = ui.Gradient.linear(p, p + const Offset(120, 40), [Color(0xFF000000 | r.nextInt(0xFFFFFF)), const Color(0x80FFFFFF)]));
}
for (var i = 0; i < 60; i++) {
final d = Rect.fromCenter(center: Offset(r.nextDouble() * s.width + 20 * math.sin(a + i), r.nextDouble() * s.height), width: 40 + 30 * t, height: 40);
c.drawImageRect(img, src, d, imgPaint);
}
for (var i = 0; i < 300; i++) {
xforms.add(RSTransform.fromComponents(rotation: a + i, scale: 0.2, anchorX: 128, anchorY: 128, translateX: r.nextDouble() * s.width, translateY: r.nextDouble() * s.height));
rects.add(src);
}
for (var i = 0; i < 10; i++) {
c.drawCircle(Offset(r.nextDouble() * s.width, r.nextDouble() * s.height), 50, shaderPaint);
}
for (var i = 0; i < 8; i++) {
final pb = ui.ParagraphBuilder(ui.ParagraphStyle(fontSize: 12.0 + i * 3))
..pushStyle(ui.TextStyle(color: const Color(0xFFFFFFFF)))
..addText('frame $frame · ${(t * 1000).toStringAsFixed(1)} · αβγ 0123456789 ${r.nextInt(1 << 30)}');
final para = pb.build()..layout(const ui.ParagraphConstraints(width: 600));
c.drawParagraph(para, Offset(r.nextDouble() * s.width * 0.5, r.nextDouble() * s.height));
}
}
c.drawAtlas(img, xforms, rects, null, null, null, imgPaint);
}
@override
bool shouldRepaint(HeavyPainter old) => true;
}windows/runner/main.cpp
// Repro runner: the main window renders continuously; additional top-level
// windows, each with its own FlutterViewController (a second engine sharing
// the process-wide EGLDisplay), are created on the platform thread, the way
// desktop_multi_window 0.3.0 does it. Engines are never destroyed.
//
// Flags (also visible to Dart): --count=N engines to create, --trigger=timer
// (every --interval ms) or --trigger=frames (on every --every'th main-window
// frame), --linger=ms after the last one, --log=path.
#include <flutter/binary_messenger.h>
#include <flutter/dart_project.h>
#include <flutter/flutter_view_controller.h>
#include <share.h>
#include <windows.h>
#include <cstdarg>
#include <cstdio>
#include <cstring>
#include <memory>
#include <string>
#include <vector>
#include "flutter_window.h"
#include "utils.h"
static int g_count = 30, g_interval = 500, g_every = 30, g_linger = 3000;
static bool g_frame_trigger = false;
static FILE* g_log = nullptr;
static ULONGLONG g_t0 = 0;
static long long g_frames = 0;
static std::vector<std::unique_ptr<FlutterWindow>> g_windows;
static void Log(const char* fmt, ...) {
if (!g_log) return;
fprintf(g_log, "%8llu ms frames=%lld ", GetTickCount64() - g_t0, g_frames);
va_list ap;
va_start(ap, fmt);
vfprintf(g_log, fmt, ap);
va_end(ap);
fputc('\n', g_log);
fflush(g_log);
}
// Exit without tearing engines down: teardown is a different race.
static void CALLBACK Finish(HWND, UINT, UINT_PTR, DWORD) {
Log("SURVIVED engines=%zu", g_windows.size());
fclose(g_log);
::TerminateProcess(::GetCurrentProcess(), 0);
}
static void CreateSecondary() {
if (static_cast<int>(g_windows.size()) >= g_count) return;
int id = static_cast<int>(g_windows.size()) + 1;
flutter::DartProject project(L"data");
project.set_dart_entrypoint_arguments({"secondary", std::to_string(id)});
auto window = std::make_unique<FlutterWindow>(project);
Log("engine %d create begin", id);
bool ok = window->Create(L"secondary", Win32Window::Point(700 + 15 * (id % 20), 80 + 15 * (id % 20)),
Win32Window::Size(480, 320));
Log("engine %d create end ok=%d", id, ok ? 1 : 0);
g_windows.push_back(std::move(window));
if (static_cast<int>(g_windows.size()) == g_count) ::SetTimer(nullptr, 0, g_linger, Finish);
}
static void CALLBACK OnTimer(HWND, UINT, UINT_PTR id, DWORD) {
CreateSecondary();
if (static_cast<int>(g_windows.size()) >= g_count) ::KillTimer(nullptr, id);
}
int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
_In_ wchar_t* command_line, _In_ int show_command) {
::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
g_t0 = GetTickCount64();
std::vector<std::string> args = GetCommandLineArguments();
std::wstring log_path;
for (const std::string& a : args) {
auto val = [&](const char* name) { return a.substr(strlen(name)); };
if (a.rfind("--count=", 0) == 0) g_count = std::stoi(val("--count="));
if (a.rfind("--interval=", 0) == 0) g_interval = std::stoi(val("--interval="));
if (a.rfind("--every=", 0) == 0) g_every = std::stoi(val("--every="));
if (a.rfind("--linger=", 0) == 0) g_linger = std::stoi(val("--linger="));
if (a == "--trigger=frames") g_frame_trigger = true;
if (a.rfind("--log=", 0) == 0) log_path = std::wstring(a.begin() + 6, a.end());
}
if (log_path.empty()) {
wchar_t exe[MAX_PATH];
::GetModuleFileNameW(nullptr, exe, MAX_PATH);
log_path = std::wstring(exe);
log_path = log_path.substr(0, log_path.find_last_of(L'\\') + 1) + L"repro_log.txt";
}
g_log = _wfsopen(log_path.c_str(), L"w", _SH_DENYNO);
Log("start pid=%lu count=%d trigger=%s interval=%d every=%d", ::GetCurrentProcessId(), g_count,
g_frame_trigger ? "frames" : "timer", g_interval, g_every);
flutter::DartProject project(L"data");
project.set_dart_entrypoint_arguments(args);
FlutterWindow window(project);
if (!window.Create(L"angle_race_repro", Win32Window::Point(10, 10), Win32Window::Size(1280, 720))) {
return EXIT_FAILURE;
}
window.SetQuitOnClose(true);
window.controller()->engine()->messenger()->SetMessageHandler(
"repro/frames", [](const uint8_t* msg, size_t size, flutter::BinaryReply reply) {
if (size == 8) memcpy(&g_frames, msg, 8);
if (g_frames % 300 == 0) Log("heartbeat");
if (g_frame_trigger && g_frames >= 120 && g_frames % g_every == 0) CreateSecondary();
reply(nullptr, 0);
});
if (!g_frame_trigger) ::SetTimer(nullptr, 0, g_interval, OnTimer);
::MSG msg;
while (::GetMessage(&msg, nullptr, 0, 0)) {
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
::CoUninitialize();
return EXIT_SUCCESS;
}windows/runner/flutter_window.h (added to the public section)
flutter::FlutterViewController* controller() { return flutter_controller_.get(); }Flutter Doctor output
flutter doctor -v
[!] Flutter (Channel [user-branch], 3.50.1, on Microsoft Windows [Version 10.0.26300.9974], locale en-GB)
• Framework revision ae9b586f34, 2026-11-18 17:01:07 -0800
• Engine revision 4d35714800
• Dart version 3.14.0
• DevTools version 2.61.0
[✓] Windows Version (Windows 11 or higher, 26H2, 2009)
[X] Android toolchain - develop for Android devices
X Unable to locate Android SDK.
[✓] Visual Studio - develop Windows apps (Visual Studio Build Tools 2022 17.14.42)
• Visual Studio Build Tools 2022 version 17.14.37806.7
• Windows 10 SDK version 10.0.26100.0
[✓] Connected device (3 available)
[✓] Network resources
The SDK is a shallow clone of the 3.50.1 tag, hence the unknown channel. The comparison build used 3.47.9 (framework c197ca5, engine 89c39ed).
Activity
loic-sharma commentedon Nov 24, 2026
@NickDA225,can you check if you can reproduce this on the
mainchannel?You can switch to main using:
NickDA225 commentedon Nov 25, 2026
Yes, it reproduces on main.
438539fe96(3.51.0-0.2.pre, engine38edca745b), which includes #196897 and still pins ANGLEa8d74ca3. Same repro, same machine, 20 runs per row, with a 3.50.1 control run in the same session:--trigger=frames, Intel UHD 770--trigger=timer --interval=500, Intel UHD 770--trigger=timer --interval=500, NVIDIA T1000Symbolicated with the main SDK's release PDB, every crash is in the same ANGLE D3D11 draw-state path, under
GL_DrawElementson the raster thread (StateManager11::updateState/syncUniformBuffersForShader/syncFramebuffer,ProgramExecutableD3D::getUsedImageRange,VertexArray11). The new engine is in theEmbedderSurfaceGLImpellerconstructor or its firstCompositorOpenGL::Present. So the multithread-protection change doesn't cover this cross-engine path.loic-sharma commentedon Nov 25, 2026
Thanks for confirming @NickDA225.
@mattkae This crash is caused by ANGLE's bug and still happens even after the D3D11 multithread mitigation. We should confirm this is fixed when we roll ANGLE with the upstream fix: #197238. I'll go ahead and assign this one to you too. Happy Thanksgiving 😅
cc @gaaclarke
gaaclarke commentedon Nov 25, 2026
I added this data point to the ANGLE bug: https://g-issues.angleproject.org/issues/587081198