Skip to content

[Windows] Crash in GPU texture callback after asynchronous UnregisterTexture #397

Closed

Description

@JulienDev

Describe the bug

I encountered a native Windows crash during normal live playback with FVP 0.38.1. The application exits with a null read inside fvp.dll on Flutter's raster thread.

WER / WinDbg details:

  • exception: 0xc0000005 (read from address 0x0)
  • faulting module: fvp.dll 0.38.1.0
  • fault offset: fvp.dll+0xd34a
  • RCX = 0
  • faulting instruction: mov rax, qword ptr [rcx]
  • Flutter 3.41.9
  • Windows x64
  • mdk 0.38.0, build 4540373

The relevant disassembly maps exactly to the Windows GPU surface descriptor callback:

mov rdx, [rbx+8]
mov rcx, [rdx+788h]   ; ctx (null)
mov r8,  [rdx+780h]   ; rt
mov rdx, [rdx+778h]   ; tex
mov rax, [rcx]        ; crash
call [rax+178h]       ; ID3D11DeviceContext::CopyResource
mov rax, [rbx+8]
mov rcx, [rax+788h]
mov rax, [rcx]
call [rax+378h]       ; ID3D11DeviceContext::Flush

This matches:

ctx->CopyResource(tex.Get(), rt.Get());
ctx->Flush();

I think there is a lifetime race in ReleaseRT. Flutter documents TextureRegistrar::UnregisterTexture as asynchronous, but the current code uses the deprecated overload and immediately erases the last stored shared_ptr<TexturePlayer>:

texture_registrar_->UnregisterTexture(texId);
players_.erase(it);

The raster thread may therefore still enter the descriptor callback, which captures this, after the TexturePlayer and its D3D COM members have started being destroyed.

I prepared this local change, which compiles successfully in Windows Release builds:

if (auto it = players_.find(texId); it != players_.cend()) {
    auto player = it->second;
    texture_registrar_->UnregisterTexture(texId, [player]() {});
    players_.erase(it);
} else {
    texture_registrar_->UnregisterTexture(texId, []() {});
}

I also added a defensive null check before CopyResource, although keeping the callback owner alive until unregistration completes appears to be the actual fix.

Expected behavior

Releasing or replacing a Windows texture should not allow Flutter's raster thread to call a descriptor callback after its owner has been destroyed.

Would you agree with using the asynchronous completion callback to retain TexturePlayer? I can prepare a PR if useful.

I can provide additional sanitized WinDbg output if needed, but I have not attached the user minidump.

Thanks

Activity

  1. wang-bin commented on Sep 17, 2026

    @wang-bin
    Owner

    agree, player should be destroyed after texture is actually removed. patch is welcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions