Skip to content

Commit dcfb9ed

Browse files
Check for overwriting existing SRB pointer in CreateShaderResourceBinding
1 parent 977d540 commit dcfb9ed

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2022 Diligent Graphics LLC
2+
* Copyright 2019-2024 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -524,6 +524,13 @@ class PipelineResourceSignatureBase : public DeviceObjectBase<typename EngineImp
524524
virtual void DILIGENT_CALL_TYPE CreateShaderResourceBinding(IShaderResourceBinding** ppShaderResourceBinding,
525525
bool InitStaticResources) override final
526526
{
527+
if (ppShaderResourceBinding == nullptr)
528+
{
529+
DEV_ERROR("ppShaderResourceBinding must not be null");
530+
return;
531+
}
532+
DEV_CHECK_ERR(*ppShaderResourceBinding == nullptr, "Overwriting existing shader resource binding pointer may cause memory leaks.");
533+
527534
auto* pThisImpl{static_cast<PipelineResourceSignatureImplType*>(this)};
528535
auto& SRBAllocator{pThisImpl->GetDevice()->GetSRBAllocator()};
529536
auto* pResBindingImpl{NEW_RC_OBJ(SRBAllocator, "ShaderResourceBinding instance", ShaderResourceBindingImplType)(pThisImpl)};

Graphics/GraphicsEngine/include/PipelineStateBase.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,13 @@ class PipelineStateBase : public DeviceObjectBase<typename EngineImplTraits::Pip
568568
virtual void DILIGENT_CALL_TYPE CreateShaderResourceBinding(IShaderResourceBinding** ppShaderResourceBinding,
569569
bool InitStaticResources) override final
570570
{
571+
if (ppShaderResourceBinding == nullptr)
572+
{
573+
DEV_ERROR("ppShaderResourceBinding must not be null");
574+
return;
575+
}
576+
DEV_CHECK_ERR(*ppShaderResourceBinding == nullptr, "Overwriting existing shader resource binding pointer may cause a memory leak.");
577+
571578
CheckPipelineReady();
572579

573580
*ppShaderResourceBinding = nullptr;

0 commit comments

Comments
 (0)