fix bug that blocked stopping scene #12

This commit is contained in:
hecomi
2017-01-06 04:02:24 +09:00
parent 4de8f0ba51
commit 29920b6b94
4 changed files with 10 additions and 8 deletions
@@ -214,9 +214,11 @@ bool Duplicator::Duplicate()
{ {
if (!dupl_ || !device_) return false; if (!dupl_ || !device_) return false;
const UINT timeout = 16;
ComPtr<IDXGIResource> resource; ComPtr<IDXGIResource> resource;
DXGI_OUTDUPL_FRAME_INFO frameInfo; DXGI_OUTDUPL_FRAME_INFO frameInfo;
const auto hr = dupl_->AcquireNextFrame(INFINITE, &frameInfo, &resource); const auto hr = dupl_->AcquireNextFrame(timeout, &frameInfo, &resource);
if (FAILED(hr)) if (FAILED(hr))
{ {
@@ -228,32 +230,31 @@ bool Duplicator::Duplicate()
// it is necessary to re-initialize monitors. // it is necessary to re-initialize monitors.
Debug::Log("Duplicator::Duplicate() => DXGI_ERROR_ACCESS_LOST."); Debug::Log("Duplicator::Duplicate() => DXGI_ERROR_ACCESS_LOST.");
state_ = State::AccessLost; state_ = State::AccessLost;
break; return false;
} }
case DXGI_ERROR_WAIT_TIMEOUT: case DXGI_ERROR_WAIT_TIMEOUT:
{ {
// This often occurs when timeout value is small and it is not problem. // This often occurs when timeout value is small and it is not problem.
// Debug::Log("Duplicator::Duplicate() => DXGI_ERROR_WAIT_TIMEOUT."); // Debug::Log("Duplicator::Duplicate() => DXGI_ERROR_WAIT_TIMEOUT.");
break; return true;
} }
case DXGI_ERROR_INVALID_CALL: case DXGI_ERROR_INVALID_CALL:
{ {
Debug::Error("Duplicator::Duplicate() => DXGI_ERROR_INVALID_CALL."); Debug::Error("Duplicator::Duplicate() => DXGI_ERROR_INVALID_CALL.");
break; return false;
} }
case E_INVALIDARG: case E_INVALIDARG:
{ {
Debug::Error("Duplicator::Duplicate() => E_INVALIDARG."); Debug::Error("Duplicator::Duplicate() => E_INVALIDARG.");
break; return false;
} }
default: default:
{ {
state_ = State::Unknown; state_ = State::Unknown;
Debug::Error("Duplicator::Duplicate() => Unknown Error."); Debug::Error("Duplicator::Duplicate() => Unknown Error.");
break; return false;
} }
} }
return false;
} }
ScopedReleaser releaser([this] ScopedReleaser releaser([this]
@@ -3,6 +3,7 @@
#include <d3d11.h> #include <d3d11.h>
#include <dxgi1_2.h> #include <dxgi1_2.h>
#include <memory> #include <memory>
#include <atomic>
#include <thread> #include <thread>
#include <mutex> #include <mutex>
#include <wrl/client.h> #include <wrl/client.h>
@@ -73,7 +74,7 @@ private:
void UpdateDirtyRects(); void UpdateDirtyRects();
Monitor* monitor_ = nullptr; Monitor* monitor_ = nullptr;
State state_ = State::Ready; std::atomic<State> state_ = State::Ready;
std::shared_ptr<class IsolatedD3D11Device> device_; std::shared_ptr<class IsolatedD3D11Device> device_;
Microsoft::WRL::ComPtr<IDXGIOutputDuplication> dupl_; Microsoft::WRL::ComPtr<IDXGIOutputDuplication> dupl_;