Skip to content

Commit

Permalink
Fix memory leak with assembly buffer (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
elishacloud authored Mar 10, 2024
1 parent 1bcbeca commit 7df94af
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions source/d3d8to9_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2009,20 +2009,29 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::CreatePixelShader(const DWORD *pFunct
NewSourceCode.insert(PhasePosition, " phase\n");

// If no errors were encountered then check if code assembles
if (!ConvertError)
if (!ConvertError && D3DXAssembleShader != nullptr)
{
// Test if ps_1_4 assembles
if (SUCCEEDED(D3DXAssembleShader(NewSourceCode.data(), static_cast<UINT>(NewSourceCode.size()), nullptr, nullptr, 0, &Assembly, &ErrorBuffer)))
{
SourceCode = NewSourceCode;
Assembly->Release();
Assembly = nullptr;
}
else
{
#ifndef D3D8TO9NOLOG
LOG << "> Failed to convert shader to ps_1_4" << std::endl;
LOG << "> Dumping translated shader assembly:" << std::endl << std::endl << NewSourceCode << std::endl;
LOG << "> Failed to reassemble shader:" << std::endl << std::endl << static_cast<const char *>(ErrorBuffer->GetBufferPointer()) << std::endl;
#endif
if (ErrorBuffer != nullptr)
{
#ifndef D3D8TO9NOLOG
LOG << "> Failed to reassemble shader:" << std::endl << std::endl << static_cast<const char*>(ErrorBuffer->GetBufferPointer()) << std::endl;
#endif
ErrorBuffer->Release();
ErrorBuffer = nullptr;
}
}
}
}
Expand Down Expand Up @@ -2078,6 +2087,8 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::CreatePixelShader(const DWORD *pFunct

hr = ProxyInterface->CreatePixelShader(static_cast<const DWORD *>(Assembly->GetBufferPointer()), reinterpret_cast<IDirect3DPixelShader9 **>(pHandle));

Assembly->Release();

if (FAILED(hr))
{
#ifndef D3D8TO9NOLOG
Expand Down

0 comments on commit 7df94af

Please sign in to comment.