浏览代码

libobs-winrt: Improve error logging code

Use code() instead of to_abi() on hresult_error structs as the latter
has additional side effects. Cast all values to int32_t to ensure the
hresult int32_t() operator is called so we pass the actual value and not
the full struct (detected by PVS Studio).
Richard Stanway 4 年之前
父节点
当前提交
30257c9fe3
共有 2 个文件被更改,包括 34 次插入31 次删除
  1. 28 26
      libobs-winrt/winrt-capture.cpp
  2. 6 5
      libobs-winrt/winrt-dispatch.cpp

+ 28 - 26
libobs-winrt/winrt-capture.cpp

@@ -19,12 +19,12 @@ try {
 		IsApiContractPresent(L"Windows.Foundation.UniversalApiContract",
 				     8);
 } catch (const winrt::hresult_error &err) {
-	blog(LOG_ERROR, "winrt_capture_supported (0x%08X): %ls", err.to_abi(),
-	     err.message().c_str());
+	blog(LOG_ERROR, "winrt_capture_supported (0x%08X): %ls",
+	     (int32_t)err.code(), err.message().c_str());
 	return false;
 } catch (...) {
 	blog(LOG_ERROR, "winrt_capture_supported (0x%08X)",
-	     winrt::to_hresult());
+	     (int32_t)winrt::to_hresult());
 	return false;
 }
 
@@ -36,11 +36,11 @@ try {
 			L"IsCursorCaptureEnabled");
 } catch (const winrt::hresult_error &err) {
 	blog(LOG_ERROR, "winrt_capture_cursor_toggle_supported (0x%08X): %ls",
-	     err.to_abi(), err.message().c_str());
+	     (int32_t)err.code(), err.message().c_str());
 	return false;
 } catch (...) {
 	blog(LOG_ERROR, "winrt_capture_cursor_toggle_supported (0x%08X)",
-	     winrt::to_hresult());
+	     (int32_t)winrt::to_hresult());
 	return false;
 }
 
@@ -239,20 +239,20 @@ static void winrt_capture_device_loss_release(void *data)
 	} catch (winrt::hresult_error &err) {
 		blog(LOG_ERROR,
 		     "Direct3D11CaptureFramePool::Close (0x%08X): %ls",
-		     err.to_abi(), err.message().c_str());
+		     (int32_t)err.code(), err.message().c_str());
 	} catch (...) {
 		blog(LOG_ERROR, "Direct3D11CaptureFramePool::Close (0x%08X)",
-		     winrt::to_hresult());
+		     (int32_t)winrt::to_hresult());
 	}
 
 	try {
 		capture->session.Close();
 	} catch (winrt::hresult_error &err) {
 		blog(LOG_ERROR, "GraphicsCaptureSession::Close (0x%08X): %ls",
-		     err.to_abi(), err.message().c_str());
+		     (int32_t)err.code(), err.message().c_str());
 	} catch (...) {
 		blog(LOG_ERROR, "GraphicsCaptureSession::Close (0x%08X)",
-		     winrt::to_hresult());
+		     (int32_t)winrt::to_hresult());
 	}
 
 	capture->session = nullptr;
@@ -271,11 +271,11 @@ try {
 			L"IsBorderRequired");
 } catch (const winrt::hresult_error &err) {
 	blog(LOG_ERROR, "winrt_capture_border_toggle_supported (0x%08X): %ls",
-	     err.to_abi(), err.message().c_str());
+	     (int32_t)err.code(), err.message().c_str());
 	return false;
 } catch (...) {
 	blog(LOG_ERROR, "winrt_capture_border_toggle_supported (0x%08X)",
-	     winrt::to_hresult());
+	     (int32_t)winrt::to_hresult());
 	return false;
 }
 #endif
@@ -297,10 +297,10 @@ winrt_capture_create_item(IGraphicsCaptureItemInterop *const interop_factory,
 				blog(LOG_ERROR, "CreateForWindow (0x%08X)", hr);
 		} catch (winrt::hresult_error &err) {
 			blog(LOG_ERROR, "CreateForWindow (0x%08X): %ls",
-			     err.to_abi(), err.message().c_str());
+			     (int32_t)err.code(), err.message().c_str());
 		} catch (...) {
 			blog(LOG_ERROR, "CreateForWindow (0x%08X)",
-			     winrt::to_hresult());
+			     (int32_t)winrt::to_hresult());
 		}
 	} else {
 		assert(monitor);
@@ -317,10 +317,10 @@ winrt_capture_create_item(IGraphicsCaptureItemInterop *const interop_factory,
 				     hr);
 		} catch (winrt::hresult_error &err) {
 			blog(LOG_ERROR, "CreateForMonitor (0x%08X): %ls",
-			     err.to_abi(), err.message().c_str());
+			     (int32_t)err.code(), err.message().c_str());
 		} catch (...) {
 			blog(LOG_ERROR, "CreateForMonitor (0x%08X)",
-			     winrt::to_hresult());
+			     (int32_t)winrt::to_hresult());
 		}
 	}
 
@@ -390,10 +390,11 @@ static void winrt_capture_device_loss_rebuild(void *device_void, void *data)
 		session.StartCapture();
 		capture->active = TRUE;
 	} catch (winrt::hresult_error &err) {
-		blog(LOG_ERROR, "StartCapture (0x%08X): %ls", err.to_abi(),
-		     err.message().c_str());
+		blog(LOG_ERROR, "StartCapture (0x%08X): %ls",
+		     (int32_t)err.code(), err.message().c_str());
 	} catch (...) {
-		blog(LOG_ERROR, "StartCapture (0x%08X)", winrt::to_hresult());
+		blog(LOG_ERROR, "StartCapture (0x%08X)",
+		     (int32_t)winrt::to_hresult());
 	}
 }
 
@@ -492,11 +493,12 @@ try {
 	return capture;
 
 } catch (const winrt::hresult_error &err) {
-	blog(LOG_ERROR, "winrt_capture_init (0x%08X): %ls", err.to_abi(),
+	blog(LOG_ERROR, "winrt_capture_init (0x%08X): %ls", (int32_t)err.code(),
 	     err.message().c_str());
 	return nullptr;
 } catch (...) {
-	blog(LOG_ERROR, "winrt_capture_init (0x%08X)", winrt::to_hresult());
+	blog(LOG_ERROR, "winrt_capture_init (0x%08X)",
+	     (int32_t)winrt::to_hresult());
 	return nullptr;
 }
 
@@ -541,11 +543,11 @@ extern "C" EXPORT void winrt_capture_free(struct winrt_capture *capture)
 		} catch (winrt::hresult_error &err) {
 			blog(LOG_ERROR,
 			     "Direct3D11CaptureFramePool::Close (0x%08X): %ls",
-			     err.to_abi(), err.message().c_str());
+			     (int32_t)err.code(), err.message().c_str());
 		} catch (...) {
 			blog(LOG_ERROR,
 			     "Direct3D11CaptureFramePool::Close (0x%08X)",
-			     winrt::to_hresult());
+			     (int32_t)winrt::to_hresult());
 		}
 
 		try {
@@ -553,11 +555,11 @@ extern "C" EXPORT void winrt_capture_free(struct winrt_capture *capture)
 		} catch (winrt::hresult_error &err) {
 			blog(LOG_ERROR,
 			     "GraphicsCaptureSession::Close (0x%08X): %ls",
-			     err.to_abi(), err.message().c_str());
+			     (int32_t)err.code(), err.message().c_str());
 		} catch (...) {
 			blog(LOG_ERROR,
 			     "GraphicsCaptureSession::Close (0x%08X)",
-			     winrt::to_hresult());
+			     (int32_t)winrt::to_hresult());
 		}
 
 		delete capture;
@@ -614,11 +616,11 @@ extern "C" EXPORT BOOL winrt_capture_show_cursor(struct winrt_capture *capture,
 	} catch (winrt::hresult_error &err) {
 		blog(LOG_ERROR,
 		     "GraphicsCaptureSession::IsCursorCaptureEnabled (0x%08X): %ls",
-		     err.to_abi(), err.message().c_str());
+		     (int32_t)err.code(), err.message().c_str());
 	} catch (...) {
 		blog(LOG_ERROR,
 		     "GraphicsCaptureSession::IsCursorCaptureEnabled (0x%08X)",
-		     winrt::to_hresult());
+		     (int32_t)winrt::to_hresult());
 	}
 
 	return success;

+ 6 - 5
libobs-winrt/winrt-dispatch.cpp

@@ -43,10 +43,10 @@ extern "C" EXPORT struct winrt_disaptcher *winrt_dispatcher_init()
 		}
 	} catch (const winrt::hresult_error &err) {
 		blog(LOG_ERROR, "winrt_dispatcher_init (0x%08X): %ls",
-		     err.to_abi(), err.message().c_str());
+		     (int32_t)err.code(), err.message().c_str());
 	} catch (...) {
 		blog(LOG_ERROR, "winrt_dispatcher_init (0x%08X)",
-		     winrt::to_hresult());
+		     (int32_t)winrt::to_hresult());
 	}
 
 	return dispatcher;
@@ -57,8 +57,9 @@ winrt_dispatcher_free(struct winrt_disaptcher *dispatcher)
 try {
 	delete dispatcher;
 } catch (const winrt::hresult_error &err) {
-	blog(LOG_ERROR, "winrt_dispatcher_free (0x%08X): %ls", err.to_abi(),
-	     err.message().c_str());
+	blog(LOG_ERROR, "winrt_dispatcher_free (0x%08X): %ls",
+	     (int32_t)err.code(), err.message().c_str());
 } catch (...) {
-	blog(LOG_ERROR, "winrt_dispatcher_free (0x%08X)", winrt::to_hresult());
+	blog(LOG_ERROR, "winrt_dispatcher_free (0x%08X)",
+	     (int32_t)winrt::to_hresult());
 }