From 7a7723bdd3e144cf1e5cf6264ea04970d338990c Mon Sep 17 00:00:00 2001 From: Kai Angulo Date: Mon, 14 Oct 2024 02:23:11 -0700 Subject: [PATCH] Add HRESULT check to machDxcCompileResultGet* functions --- src/mach_dxc.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/mach_dxc.cpp b/src/mach_dxc.cpp index 63d7a00..4a04731 100644 --- a/src/mach_dxc.cpp +++ b/src/mach_dxc.cpp @@ -21,6 +21,7 @@ #include #include "mach_dxc.h" +#include "dxc/Support/FileIOHelper.h" #ifdef __cplusplus extern "C" { @@ -180,21 +181,27 @@ MACH_EXPORT MachDxcCompileResult machDxcCompile( MACH_EXPORT MachDxcCompileError machDxcCompileResultGetError(MachDxcCompileResult err) { CComPtr pCompileResult = CComPtr(reinterpret_cast(err)); - CComPtr pErrors; - pCompileResult->GetOutput(DXC_OUT_ERRORS, IID_PPV_ARGS(&pErrors), nullptr); - if (pErrors && pErrors->GetStringLength() > 0) { + + CComPtr pErrors = nullptr; + HRESULT hr = pCompileResult->GetErrorBuffer(&pErrors); + + if (hr == S_OK && !hlsl::IsBlobNullOrEmpty(pErrors)) { return reinterpret_cast(pErrors.Detach()); } + return nullptr; } MACH_EXPORT MachDxcCompileObject machDxcCompileResultGetObject(MachDxcCompileResult err) { CComPtr pCompileResult = CComPtr(reinterpret_cast(err)); - CComPtr pObject; - pCompileResult->GetOutput(DXC_OUT_OBJECT, IID_PPV_ARGS(&pObject), nullptr); - if (pObject && pObject->GetBufferSize() > 0) { + + CComPtr pObject = nullptr; + HRESULT hr = pCompileResult->GetResult(&pObject); + + if (hr == S_OK && !hlsl::IsBlobNullOrEmpty(pObject)) { return reinterpret_cast(pObject.Detach()); } + return nullptr; }