Skip to content

Crash on Windows, stable 3.13.* versions, framebuffer nullptr when rendering #137973

@fufesou

Description

@fufesou

Is there an existing issue for this?

Steps to reproduce

No steps, just run the multiple window example on windows, see MixinNetwork/flutter-plugins#283

When creating a new flutter::FlutterViewController, EGL_MakeCurrent will be called, then current rendering context will be unset.

Crash description

  1. SuerfaceFrame::Submit() requires framebuffer to be not nullptr.
    Framebuffer *framebuffer = state.getDrawFramebuffer();
    ASSERT(framebuffer);

    if (context->getLimitations().noSeparateStencilRefsAndMasks ||
        extensions.webglCompatibilityANGLE)
    {
        ASSERT(framebuffer);
        const FramebufferAttachment *dsAttachment =
            framebuffer->getStencilOrDepthStencilAttachment();
        const GLuint stencilBits = dsAttachment ? dsAttachment->getStencilSize() : 0;
        ASSERT(stencilBits <= 8);
...
  1. FlutterViewController will reset frameBuffer by calling State::setDrawFramebufferBinding()

Crash case

SurfaceFrame::Submit() -> OpsTask::onExecute() -> [ renderPass->begin(); chain.head()->execute(flushState, chain.bounds()); ]

renderPass->begin(); will prepare the framebuffer, then chain.head()->execute(flushState, chain.bounds()); will execute with no error.

But there's no guarantee that no other threads call State::setDrawFramebufferBinding() between the two calls.

No crash case

If State::setDrawFramebufferBinding() is not executed between renderPass->begin(); and chain.head()->execute(flushState, chain.bounds());

                             Thread 1                     |                                   Thread2
-------------------------------------------------------------------------------------------------------------------------
        OpsTask::onExecute()                              |
                                                          |
        renderPass->begin();                              |
                                                          |
 chain.head()->execute(flushState, chain.bounds());       |
                                                          |
                                                          |     State::setDrawFramebufferBinding()  from FlutterViewController()
Crash case
                             Thread 1                     |                                   Thread2
-------------------------------------------------------------------------------------------------------------------------
        OpsTask::onExecute()                              |
                                                          |
        renderPass->begin();                              |
                                                          |
                                                          |     State::setDrawFramebufferBinding()  from FlutterViewController()
                                                          |
 chain.head()->execute(flushState, chain.bounds());       |
                                                          |
                                                       Crash
https://github.com/google/angle/blob/eebf069c1d98952c9cde6f4e5f81383736b10163/src/libANGLE/validationES.cpp#L4124

Callstacks

Crash callstack

See the image attached in MixinNetwork/flutter-plugins#283.

Reset frameBuffer

Creating FlutterViewController will cause the global render context to reset the framebuffer by calling EGL_MakeCurrent then ANGLE_TRY(unsetDefaultFramebuffer());

State::setDrawFramebufferBinding 15424, 000001EA9A854AB0, framebuffer: 0000000000000000
[0] gl::State::setDrawFramebufferBinding
[1] gl::Context::unsetDefaultFramebuffer
[2] gl::Context::unMakeCurrent
[3] egl::Display::makeCurrent
[4] egl::MakeCurrent
[5] EGL_MakeCurrent
[6] flutter::AngleSurfaceManager::SetVSyncEnabled
[7] flutter::AngleSurfaceManager::CreateSurface
[8] flutter::FlutterWindowsView::CreateRenderSurface
[9] FlutterDesktopViewControllerCreate
[10] DesktopMultiWindowSetWindowCreatedCallback
[11] DesktopMultiWindowPluginRegisterWithRegistrar
[12] DesktopMultiWindowPluginRegisterWithRegistrar
[13] DesktopMultiWindowPluginRegisterWithRegistrar
[14] DesktopMultiWindowPluginRegisterWithRegistrar
[15] DesktopMultiWindowPluginRegisterWithRegistrar
[16] DesktopMultiWindowPluginRegisterWithRegistrar
[17] DesktopMultiWindowSetWindowCreatedCallback
[18] flutter::IncomingMessageDispatcher::HandleMessage
[19] flutter::FlutterWindowsEngine::HandlePlatformMessage
[20] std::_Func_impl_no_alloc<`lambda at ../../flutter/shell/platform/embedder/embedder.cc:1874:9',void,std::unique_ptr<flutter::PlatformMessage,std::default_delete<flutter::PlatformMessage> > >::_Do_call
[21] std::_Func_class<void,std::unique_ptr<flutter::PlatformMessage,std::default_delete<flutter::PlatformMessage> > >::operator()
[22] flutter::PlatformViewEmbedder::HandlePlatformMessage
[23] fml::internal::CopyableLambda<`lambda at ../../flutter/shell/platform/embedder/platform_view_embedder.cc:24:9'>::operator()<>
[24] flutter::EmbedderTaskRunner::PostTask
[25] flutter::EmbedderThreadHost::PostTask
[26] FlutterEngineRunTask
[27] std::_Func_impl_no_alloc<`lambda at ../../flutter/shell/platform/windows/flutter_windows_engine.cc:171:41',void,const FlutterTask *>::_Do_call
[28] flutter::TaskRunner::ProcessTasks
[29] flutter::TaskRunnerWindow::ProcessTasks
[30] flutter::TaskRunnerWindow::HandleMessage
[31] CallWindowProcW
[32] DispatchMessageW
[33] DispatchMessageW
[34] DispatchMessageW
[35] BaseThreadInitThunk
[36] RtlUserThreadStart

Expected results

No crash.

It's a critical crash. Can you please do a fix to the stable version?
I can't submit a PR to the main branch because the changes are too big.

And I'm not sure if it is better to do check framebuffer and return, or add a mutex lock in the flutter engine.

Actual results

Crash because framebuffer sometimes is nullptr.

Code sample

Code sample

I don't know under what circumstances it is necessary to new a flutter::FlutterViewController, but in the case of multiple windows on the desktop, this is indeed needed.

Run this example https://github.com/MixinNetwork/flutter-plugins/tree/main/packages/desktop_multi_window/example

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[√] Flutter (Channel stable, 3.13.9, on Microsoft Windows [Version 10.0.20348.1906], locale en-US)
    • Flutter version 3.13.9 on channel stable at C:\Users\Administrator\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision d211f42860 (12 days ago), 2023-10-25 13:42:25 -0700
    • Engine revision 0545f8705d
    • Dart version 3.1.5
    • DevTools version 2.25.0

[√] Windows Version (Installed version of Windows is version 10 or higher)

[X] Android toolchain - develop for Android devices
    X Unable to locate Android SDK.
      Install Android Studio from: https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK components.
      (or visit https://flutter.dev/docs/get-started/install/windows#android-setup for detailed instructions).
      If the Android SDK has been installed to a custom location, please use
      `flutter config --android-sdk` to update to that location.


[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.7.6)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.7.34221.43
    • Windows 10 SDK version 10.0.22621.0

[!] Android Studio (not installed)
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/docs/get-started/install/windows#android-setup for detailed instructions).

[√] VS Code (version 1.84.0)
    • VS Code at C:\Users\Administrator\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.76.0

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.20348.1906]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 119.0.6045.106
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 119.0.2151.44

[√] Network resources
    • All expected network resources are available.

! Doctor found issues in 2 categories.

Metadata

Metadata

Assignees

Labels

a: desktopRunning on desktopc: crashStack traces logged to the consolec: regressionIt was better in the past than it is nowneeds repro infoAutomated crash report whose cause isn't yet knownplatform-windowsBuilding on or for Windows specificallyr: fixedIssue is closed as already fixed in a newer versionteam-windowsOwned by the Windows platform team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions