Repository navigation
Description
Note
November 23: This crash is mitigated on main. The mitigation will be cherry-picked to the next Flutter stable release, 3.50.2.
The fix for this crash is tracked by: #197238
Steps to reproduce
Summary
On Windows, Flutter 3.50.0 crashes with heap corruption (0xC0000374) or an access violation at address 0 (0xC0000005) a few seconds after start, in debug, profile and release, in any app that decodes images while it animates. 3.47.8 runs the same app without a crash.
At the crash, two engine threads are inside ANGLE's one D3D11 immediate context at the same time:
- the raster thread, in
eglSwapBuffers→rx::SwapChain11::present; - the IO thread, in
glFlush→rx::Renderer11::flush, fromImageDecoderImpeller::UploadTextureToPrivate.
A D3D11 immediate context isn't thread-safe, so the driver's state is corrupted. The crash then surfaces on one of the GPU driver's own threads, which makes it read as a driver bug. It isn't: turning on Direct3D's own ID3D10Multithread protection for ANGLE's device stops it, with the driver unchanged.
Steps to reproduce
flutter create --platforms=windows swap_race- Replace
lib/main.dartwith the code sample below. flutter build windows --debug(or--release) and run the executable.- Wait. It dies within about 25 seconds.
Expected results
The app keeps running, as it does on 3.47.8.
Actual results
The process dies with no Dart exception.
| Flutter | D3D11 multithread protection | Runs | Result |
|---|---|---|---|
| 3.50.0 | off | 5 | died after 7, 15, 18, 22 and 23 s |
| 3.47.8 | off | 3 | ran 60 s each (stopped by the test) |
| 3.50.0 | on (see "Confirmation") | 3 | ran 90 s each (stopped by the test) |
A larger app of ours (many images loaded at start, Flutter GPU for its sprites) dies in 3 to 7 s on 3.50.0 in debug and release, and runs on 3.47.8.
Code sample
lib/main.dart
// Minimal repro: frames presented every vsync while images are decoded and
// uploaded (the engine's IO thread) without pause.
import 'dart:async';
import 'dart:typed_data';
import 'dart:ui' as ui;
import 'package:flutter/widgets.dart';
void main() => runApp(const Race());
class Race extends StatefulWidget {
const Race({super.key});
@override
State<Race> createState() => _RaceState();
}
class _RaceState extends State<Race> with SingleTickerProviderStateMixin {
late final AnimationController _spin = AnimationController(vsync: this, duration: const Duration(seconds: 2))..repeat();
final List<ui.Image> _images = [];
int _decoded = 0;
@override
void initState() {
super.initState();
for (var i = 0; i < 4; i++) {
_decodeForever(i);
}
}
Future<void> _decodeForever(int seed) async {
const side = 256;
final pixels = Uint8List(side * side * 4);
while (mounted) {
for (var i = 0; i < pixels.length; i += 4) {
pixels[i] = (i + _decoded * 7 + seed * 50) & 255;
pixels[i + 1] = (i >> 8) & 255;
pixels[i + 2] = 128;
pixels[i + 3] = 255;
}
final done = Completer<ui.Image>();
ui.decodeImageFromPixels(pixels, side, side, ui.PixelFormat.rgba8888, done.complete);
final image = await done.future;
_decoded++;
_images.add(image);
if (_images.length > 8) _images.removeAt(0).dispose();
}
}
@override
Widget build(BuildContext context) => Directionality(
textDirection: TextDirection.ltr,
child: AnimatedBuilder(
animation: _spin,
builder: (context, _) => Stack(children: [
for (final image in _images) Positioned(left: 20.0 + 40 * _images.indexOf(image), top: 20, child: RawImage(image: image, width: 128, height: 128)),
Positioned(left: 300 + 200 * _spin.value, top: 300, child: Text('decoded $_decoded')),
]),
),
);
}Screenshots or Video
Screenshots / Video demonstration
[Upload media here]
Logs
Analysis
The two threads, from a release crash dump (exception 0xC0000374, heap failure type 8, an invalid pointer freed, raised on a driver worker thread), symbolised with the engine's flutter_windows.dll.pdb. Two dumps show the same picture.
Raster thread:
amdxx64.dll
d3d11.dll
dxgi.dll
rx::SwapChain11::present (SwapChain11.cpp:924)
rx::SurfaceD3D::swapRect (SurfaceD3D.cpp:291)
rx::SurfaceD3D::swap (SurfaceD3D.cpp:354)
egl::Surface::swap (Surface.cpp:348)
egl::SwapBuffers (egl_stubs.cpp:659)
EGL_SwapBuffers (entry_points_egl_autogen.cpp:810)
flutter::egl::Surface::SwapBuffers (shell/platform/windows/egl/surface.cc:60)
flutter::CompositorOpenGL::Present (compositor_opengl.cc:250)
flutter::FlutterWindowsEngine::Present
IO thread, at the same moment:
d3d11.dll
rx::Renderer11::flush
GL_Flush
impeller::CommandBufferGLES::OnWaitUntilScheduled
flutter::ImageDecoderImpeller::UnsafeUploadTextureToPrivate
flutter::ImageDecoderImpeller::UploadTextureToPrivate
fml::MessageLoopImpl::FlushTasks
ANGLE's worker pool was also busy linking programs (gl::Program::MainLinkTask, rx::ProgramD3D::GetPixelExecutableTask).
What changed. The ANGLE revision in DEPS moved from 84027aca9b (3.47.8) to a8d74ca3e5 (3.50.0). In src/libGLESv2/entry_points_egl_autogen.cpp, EGL_SwapBuffers used to hold the global EGL mutex across the swap:
// 84027aca9b (Flutter 3.47.8)
{
ANGLE_SCOPED_GLOBAL_LOCK();
...
{
ANGLE_EGL_SCOPED_CONTEXT_LOCK(SwapBuffers, thread, dpyPacked);
...
returnValue = SwapBuffers(thread, dpyPacked, surfacePacked);
}
}and now takes a display lock and the context lock only:
// a8d74ca3e5 (Flutter 3.50.0)
{
egl::ScopedDisplayLockAndRef dpyPackedLock = GetDisplayAndLockIfValid(dpyPacked);
...
{
ANGLE_EGL_SCOPED_CONTEXT_LOCK(SwapBuffers, thread);
...
returnValue = SwapBuffers(thread, dpyPacked, surfacePacked);
}
}The dumps show the result: whatever lock the swap now holds on the render context doesn't exclude glFlush on the resource context the IO thread uses. The IO thread's stack has egl::priv::ScopedGlobalMutexLock in it, which suggests GL calls on these shared contexts take the global mutex (SCOPED_SHARE_CONTEXT_LOCK without ANGLE_ENABLE_CONTEXT_MUTEX), a lock the swap no longer takes. I haven't confirmed which of those build defines Flutter's ANGLE is compiled with.
ANGLE's D3D11 renderer doesn't call ID3D10Multithread::SetMultithreadProtected in either revision, and upstream ANGLE main has the same EGL_SwapBuffers, so an ANGLE roll alone is unlikely to fix this.
3.50 also moved OpenGL program setup to the IO context (#185723), which gives that thread more GL work during the first frames.
It is not the SDF renderer: 3.47.8 logs Using the Impeller rendering backend (OpenGLESSDF) too and doesn't crash. (Aside: --impeller-use-sdfs=false doesn't turn SDFs off, as shell/common/switches.cc reads that switch with HasOption.)
Confirmation
To test the diagnosis without rebuilding the engine, the runner intercepted the engine's GetProcAddress(d3d11, "D3D11CreateDevice") and, on the device ANGLE created, called:
ID3D10Multithread* multithread = nullptr;
if (SUCCEEDED(context->QueryInterface(__uuidof(ID3D10Multithread),
reinterpret_cast<void**>(&multithread)))) {
multithread->SetMultithreadProtected(TRUE);
multithread->Release();
}With that one call the repro ran 90 s three times, and our larger app ran 90 s five times across debug and release, where both died within seconds without it. In a profile of the larger app the lock cost nothing measurable (raster median 2.2 to 2.3 ms with it on 3.50.0, 2.3 ms on 3.47.8 without).
Possible fixes
- Hold a lock across the swap that the resource context's GL calls also take, in the Windows embedder (
shell/platform/windows/egl) or in Flutter's ANGLE. - Or enable
ID3D10Multithreadprotection on the device inegl::Manager, which already has it (resolved_device_). This makes each D3D call atomic, which was enough to stop the crash here, though ANGLE's own D3D11 state tracking would still be touched by two threads during a present.
Flutter Doctor output
Environment
- Flutter 3.50.0 stable (framework
ab2912035e, engine371f77202a), Dart 3.14.0, DevTools 2.61.0. Control: Flutter 3.47.8 stable (framework737ba8f885). - Windows 11, version 10.0.26300, x64. Visual Studio Community 2022 17.10, Windows SDK 10.0.22621.0.
- GPU: AMD Radeon RX 6500M, driver 32.0.21045.16010, with an integrated AMD Radeon Graphics, driver 31.0.21925.1001 (a hybrid laptop). Renderer: OpenGL ES through ANGLE on D3D11.
- Not tried on NVIDIA or Intel GPUs. Concurrent use of one immediate context is undefined on any driver, so they may fail less often rather than not at all.
Activity
puneetkukreja98 commentedon Nov 17, 2026
@jerome-saltmarsh Thanks for reporting this issue. I can confirm this is a regression. I tested it on the latest master channel with Impeller both enabled and disabled, and in both cases, the app freezes/crashes.
Console logs:
flutter doctor -v:
I also tested on 3.47.8 with Impeller both enabled and disabled, and the app runs smoothly without any freezing in both cases.
flutter doctor -v:
puneetkukreja98 commentedon Nov 17, 2026
Similar issues:
#88007
#124194
#195424
[-][Windows][Impeller] 3.50 crashes within seconds when images are decoded while frames present: eglSwapBuffers no longer excludes the IO context's GL calls on ANGLE's D3D11 device[/-][+][Windows] 3.50 crashes within seconds when images are decoded while frames present: eglSwapBuffers no longer excludes the IO context's GL calls on ANGLE's D3D11 device[/+]loic-sharma commentedon Nov 18, 2026
Thanks @jerome-saltmarsh for the excellent bug report!
Summary
Flutter Windows has a crash in 3.50.0 that isn't in 3.47.8.
Stack track for Flutter's raster thread...
Stack track for Flutter's IO thread...
Flutter has two OpenGL contexts in a share group: one context on its IO thread, and a second context on the raster thread. It should be safe to do a GL call on the IO thread while also doing an EGL call on the raster thread.
This appears to be a bug in ANGLE: https://issues.angleproject.org/issues/587081198.
Turning off Impeller does not fix this bug.
Agent analysis...
Potential mitigations
SetMultithreadProtected. According to the reporter reduces the likelihood of this crash. However, my agent says this isn't a complete fix as ANGLE's C++ state is still shared without a lock. This appears to be a low risk change we could cherry pick. Here's a patch of what that might look like: https://gist.github.com/loic-sharma/370268be65175cb28a6a1349ed34448d.We've asked the ANGLE team if they have other mitigations they'd suggest.
Long-term fix
This issue likely requires a fix in ANGLE: https://issues.angleproject.org/issues/587081198
Agent analysis...
Windows: Enable D3D11 multithread protection on ANGLE's device (flutt…
7.6.2+170: build on Flutter 3.47.9, universal_ble lock back on 14a8c73
Build with Flutter 3.47.8 to avoid a GPU hang when scrolling PDFs
byteandbolt commentedon Nov 22, 2026
Another data point, since the report only covers AMD: the same race on NVIDIA, plus a hang variant and a second IO-thread path.
Environment: Flutter 3.50.0 stable (framework ab29120, engine 371f772), Windows 10 LTSC 2021 (10.0.19044), GeForce RTX 3060 (driver 461.72), profile build, Impeller (OpenGLESSDF) over ANGLE/D3D11.
Repro: pages of 40 tiles are switched every 10 frames. Each tile decodes the same 64×64 PNG with
ImmutableBuffer.fromUint8List→ImageDescriptor.encoded→instantiateCodec(targetWidth: 32, targetHeight: 32)→getNextFrame(). The images are never painted.0xC0000005The IO thread is inside
ImageDecoderImpeller::UploadTextureToPrivatein all 9 readable dumps.nvwgf2umx.dllworker thread with no Flutter frames, like the AMD case. The raster thread is inCompositorOpenGL::Present→egl::SwapBuffers. The IO thread is in one of two places:CommandBufferGLES::OnWaitUntilScheduled→GL_Flush→rx::Renderer11::flush(as reported);BlitPassGLES::EncodeCommands→ReactorGLES::React→BlitResizeTextureCommandGLES::Encode/TextureGLES::GenerateMipmap→rx::Renderer11::generateMipmapUsingD3D. So the race is not onlyglFlush.UploadTextureToPrivate→Renderer11::flush→rx::Sync11::set, while another thread waits inegl::priv::ScopedGlobalMutexLock. In the other two the raster thread waits inrx::SurfaceD3D::swap→rx::SwapChain11::present. The process never recovers. Please consider checking the hang path too when verifying theSetMultithreadProtectedfix, since that fix makes each D3D call atomic but leaves ANGLE's own state unlocked.Also seen in our larger app, on the same machine:
--no-enable-impellerfails as well (10 / 20).getNextFrame(), never fails (0 / 20).ui.Image.clone()cuts uploads per run from 2320 to 3, and the access violations go away.Symbolized stacks of all threads for every run are available on request. Full dumps too, but they contain process memory, so I'd share those privately.
loic-sharma commentedon Nov 22, 2026
Hello, this is now fixed in the
mainchannel. You can try this using:Please let us know if you can still reproduce this issue while on the
mainchannel.We will cherrypick the fix to the stable channel next: #196991.
jerome-saltmarsh commentedon Nov 23, 2026
@loic-sharma
Confirmed fixed on main (3.51.0-1.0.pre-291, framework c020570): the repro above ran 90 s in 5 debug and 3 release runs, where 3.50.0 died within 7 to 23 s, on the same AMD RX 6500M and drivers. Thanks for the quick fix!
封面像素改在 CPU 解码,减少 Windows 上加载封面时卡死后闪退:Flutter 3.50.0 升级 ANGLE 后,光栅线程的 …
gaaclarke commentedon Nov 23, 2026
@loic-sharma we should close this out now, when things are fixed on
mainthey are considered closed.loic-sharma commentedon Nov 23, 2026
@gaaclarke The PR #196897 is a mitigation, not a fix. It only addresses race conditions in D3D, but not race conditions in ANGLE. The fix requires changes in ANGLE: https://issues.angleproject.org/issues/587081198.
Since this is mitigated on main, I opened a new issue to track the fix: #197238. I'll go ahead and close this issue in favor of the new one.
Enable D3D11 multithread protection on ANGLE's device
[CP-stable]Windows: Enable D3D11 multithread protection on ANGLE's de…
loic-sharma commentedon Nov 24, 2026
Due to the US holidays, Flutter 3.50.2 will be released next week. If you are affected by this issue, you can temporarily workaround this by switching to the the
mainchannel: