d3d11: fix a crash in CommandRecordingContext::Destroy() Bug: chromium:326044506 Change-Id: Ia06ee17b29a7bd5defdcdbd84616a39e371fbe09 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/175643 Commit-Queue: Corentin Wallez <cwallez@chromium.org> Kokoro: Kokoro <noreply+kokoro@google.com> Auto-Submit: Peng Huang <penghuang@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/dawn/native/d3d11/CommandRecordingContextD3D11.cpp b/src/dawn/native/d3d11/CommandRecordingContextD3D11.cpp index d062143..5fcc396 100644 --- a/src/dawn/native/d3d11/CommandRecordingContextD3D11.cpp +++ b/src/dawn/native/d3d11/CommandRecordingContextD3D11.cpp
@@ -213,6 +213,11 @@ } void CommandRecordingContext::Destroy() { + // mDevice could be null due to failure of initialization. + if (!mDevice) { + return; + } + DAWN_ASSERT(mDevice->IsLockedByCurrentThreadIfNeeded()); mIsOpen = false; mUniformBuffer = nullptr;
diff --git a/src/dawn/native/d3d11/QueueD3D11.cpp b/src/dawn/native/d3d11/QueueD3D11.cpp index 5469cc7..5690978 100644 --- a/src/dawn/native/d3d11/QueueD3D11.cpp +++ b/src/dawn/native/d3d11/QueueD3D11.cpp
@@ -66,9 +66,11 @@ MaybeError Queue::InitializePendingContext() { // Initialize mPendingCommands. After this, calls to the use the command context // are thread safe. - CommandRecordingContext commands; - DAWN_TRY(commands.Initialize(ToBackend(GetDevice()))); - mPendingCommands.Use([&](auto pendingCommands) { *pendingCommands = std::move(commands); }); + CommandRecordingContext commandContext; + DAWN_TRY(commandContext.Initialize(ToBackend(GetDevice()))); + + mPendingCommands.Use( + [&](auto pendingCommandContext) { *pendingCommandContext = std::move(commandContext); }); // Configure the command context's uniform buffer. This is used to emulate builtins. // Creating the buffer is done outside of Initialize because it requires mPendingCommands @@ -77,6 +79,7 @@ DAWN_TRY_ASSIGN(uniformBuffer, CommandRecordingContext::CreateInternalUniformBuffer(GetDevice())); mPendingCommands->SetInternalUniformBuffer(std::move(uniformBuffer)); + return {}; }