浏览代码

libobs-winrt: Fix potential race crash

CreateForWindow can fail if the window is destroyed.
jpark37 4 年之前
父节点
当前提交
71d5451670
共有 1 个文件被更改,包括 5 次插入1 次删除
  1. 5 1
      libobs-winrt/winrt-capture.cpp

+ 5 - 1
libobs-winrt/winrt-capture.cpp

@@ -336,11 +336,15 @@ try {
 		activation_factory.as<IGraphicsCaptureItemInterop>();
 		activation_factory.as<IGraphicsCaptureItemInterop>();
 	winrt::Windows::Graphics::Capture::GraphicsCaptureItem item = {nullptr};
 	winrt::Windows::Graphics::Capture::GraphicsCaptureItem item = {nullptr};
 	try {
 	try {
-		interop_factory->CreateForWindow(
+		hr = interop_factory->CreateForWindow(
 			window,
 			window,
 			winrt::guid_of<ABI::Windows::Graphics::Capture::
 			winrt::guid_of<ABI::Windows::Graphics::Capture::
 					       IGraphicsCaptureItem>(),
 					       IGraphicsCaptureItem>(),
 			reinterpret_cast<void **>(winrt::put_abi(item)));
 			reinterpret_cast<void **>(winrt::put_abi(item)));
+		if (FAILED(hr)) {
+			blog(LOG_ERROR, "CreateForWindow (0x%08X)", hr);
+			return nullptr;
+		}
 	} catch (winrt::hresult_error &err) {
 	} catch (winrt::hresult_error &err) {
 		blog(LOG_ERROR, "CreateForWindow (0x%08X): %ls", err.to_abi(),
 		blog(LOG_ERROR, "CreateForWindow (0x%08X): %ls", err.to_abi(),
 		     err.message().c_str());
 		     err.message().c_str());