From 8a9d0b0bfb86183d120f269a538c5687665512c1 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Fri, 1 Jun 2018 00:38:15 +1000 Subject: [PATCH] [host] fix crash on screen blanking --- host/Capture/DXGI.cpp | 28 +++++++++++++++------------- host/Service.cpp | 4 +--- host/main.cpp | 2 ++ 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/host/Capture/DXGI.cpp b/host/Capture/DXGI.cpp index 3983c6f0..7f8852d8 100644 --- a/host/Capture/DXGI.cpp +++ b/host/Capture/DXGI.cpp @@ -614,7 +614,7 @@ GrabStatus Capture::DXGI::GrabFrameTexture(struct FrameInfo & frame, struct Curs return GRAB_STATUS_OK; } - if (!SUCCEEDED(status)) + if (FAILED(status)) break; m_releaseFrame = true; @@ -657,7 +657,7 @@ GrabStatus Capture::DXGI::GrabFrameTexture(struct FrameInfo & frame, struct Curs DXGI_OUTDUPL_POINTER_SHAPE_INFO shapeInfo; status = m_dup->GetFramePointerShape(m_pointerBufSize, m_pointer, &m_pointerSize, &shapeInfo); - if (!SUCCEEDED(status)) + if (FAILED(status)) { DEBUG_WINERROR("Failed to get the new pointer shape", status); return GRAB_STATUS_ERROR; @@ -681,14 +681,19 @@ GrabStatus Capture::DXGI::GrabFrameTexture(struct FrameInfo & frame, struct Curs cursor.dataSize = m_pointerSize; } - // if we also have frame data + // if we also have frame data, break out to process it if (frameInfo.LastPresentTime.QuadPart != 0) break; + // no frame data, clean up SafeRelease(&res); + ReleaseFrame(); + // if the cursor has been updated if (cursor.updated) return GRAB_STATUS_CURSOR; + + // otherwise just try again } if (SUCCEEDED(status)) @@ -762,12 +767,6 @@ GrabStatus Capture::DXGI::GrabFrameRaw(FrameInfo & frame, struct CursorInfo & cu while(true) { result = GrabFrameTexture(frame, cursor, src, timeout); - if (result != GRAB_STATUS_OK) - { - ReleaseFrame(); - return result; - } - if (timeout) { if (!m_surfaceMapped) @@ -786,10 +785,6 @@ GrabStatus Capture::DXGI::GrabFrameRaw(FrameInfo & frame, struct CursorInfo & cu break; } - m_deviceContext->CopyResource(m_texture, src); - SafeRelease(&src); - - result = ReleaseFrame(); if (result != GRAB_STATUS_OK) return result; @@ -799,6 +794,13 @@ GrabStatus Capture::DXGI::GrabFrameRaw(FrameInfo & frame, struct CursorInfo & cu m_surfaceMapped = false; } + m_deviceContext->CopyResource(m_texture, src); + SafeRelease(&src); + + result = ReleaseFrame(); + if (result != GRAB_STATUS_OK) + return result; + HRESULT status; status = m_deviceContext->Map(m_texture, 0, D3D11_MAP_READ, 0, &m_mapping); if (FAILED(status)) diff --git a/host/Service.cpp b/host/Service.cpp index 1f4f4aaf..a53284c3 100644 --- a/host/Service.cpp +++ b/host/Service.cpp @@ -183,10 +183,8 @@ bool Service::Process() // wait for the host to notify that is it is ready to proceed while (true) { - const uint8_t f = *flags; - // check if the client has flagged a restart - if (f & KVMFR_HEADER_FLAG_RESTART) + if (*flags & KVMFR_HEADER_FLAG_RESTART) { DEBUG_INFO("Restart Requested"); if (!m_capture->ReInitialize()) diff --git a/host/main.cpp b/host/main.cpp index 1e7fe4e8..4c7dcdc5 100644 --- a/host/main.cpp +++ b/host/main.cpp @@ -115,8 +115,10 @@ int run(struct StartupArgs & args) return -1; while (true) + { if (!svc->Process()) break; + } svc->DeInitialize(); return 0;