move unmap to fail guard
This commit is contained in:
committed by
ReenigneArcher
parent
f8d14ac05b
commit
026c2aebf3
@@ -130,8 +130,16 @@ test_frame_capture(dxgi::dup_t &dup, ComPtr<ID3D11Device> device) {
|
|||||||
|
|
||||||
ComPtr<IDXGIResource> frameResource;
|
ComPtr<IDXGIResource> frameResource;
|
||||||
DXGI_OUTDUPL_FRAME_INFO frameInfo;
|
DXGI_OUTDUPL_FRAME_INFO frameInfo;
|
||||||
|
ComPtr<ID3D11DeviceContext> context;
|
||||||
|
ComPtr<ID3D11Texture2D> stagingTexture;
|
||||||
|
|
||||||
HRESULT status = dup->AcquireNextFrame(500, &frameInfo, &frameResource);
|
HRESULT status = dup->AcquireNextFrame(500, &frameInfo, &frameResource);
|
||||||
auto release_frame = util::fail_guard([&dup]() {
|
device->GetImmediateContext(&context);
|
||||||
|
|
||||||
|
auto cleanup = util::fail_guard([&dup, &context, &stagingTexture]() {
|
||||||
|
if (stagingTexture) {
|
||||||
|
context->Unmap(stagingTexture.Get(), 0);
|
||||||
|
}
|
||||||
dup->ReleaseFrame();
|
dup->ReleaseFrame();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -156,15 +164,12 @@ test_frame_capture(dxgi::dup_t &dup, ComPtr<ID3D11Device> device) {
|
|||||||
frameDesc.BindFlags = 0;
|
frameDesc.BindFlags = 0;
|
||||||
frameDesc.MiscFlags = 0;
|
frameDesc.MiscFlags = 0;
|
||||||
|
|
||||||
ComPtr<ID3D11Texture2D> stagingTexture;
|
|
||||||
status = device->CreateTexture2D(&frameDesc, nullptr, &stagingTexture);
|
status = device->CreateTexture2D(&frameDesc, nullptr, &stagingTexture);
|
||||||
if (FAILED(status)) {
|
if (FAILED(status)) {
|
||||||
std::cout << "Error: Failed to create staging texture [0x"sv << util::hex(status).to_string_view() << ']' << std::endl;
|
std::cout << "Error: Failed to create staging texture [0x"sv << util::hex(status).to_string_view() << ']' << std::endl;
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
ComPtr<ID3D11DeviceContext> context;
|
|
||||||
device->GetImmediateContext(&context);
|
|
||||||
context->CopyResource(stagingTexture.Get(), frameTexture.Get());
|
context->CopyResource(stagingTexture.Get(), frameTexture.Get());
|
||||||
|
|
||||||
D3D11_MAPPED_SUBRESOURCE mappedResource;
|
D3D11_MAPPED_SUBRESOURCE mappedResource;
|
||||||
@@ -176,12 +181,10 @@ test_frame_capture(dxgi::dup_t &dup, ComPtr<ID3D11Device> device) {
|
|||||||
|
|
||||||
if (is_valid_frame(mappedResource, frameDesc)) {
|
if (is_valid_frame(mappedResource, frameDesc)) {
|
||||||
std::cout << "Frame " << (i + 1) << " is non-empty (contains visible content)." << std::endl;
|
std::cout << "Frame " << (i + 1) << " is non-empty (contains visible content)." << std::endl;
|
||||||
context->Unmap(stagingTexture.Get(), 0);
|
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "Frame " << (i + 1) << " is empty (no visible content)." << std::endl;
|
std::cout << "Frame " << (i + 1) << " is empty (no visible content)." << std::endl;
|
||||||
context->Unmap(stagingTexture.Get(), 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// All frames were empty, indicating potential capture issues.
|
// All frames were empty, indicating potential capture issues.
|
||||||
|
|||||||
Reference in New Issue
Block a user