Hi,
I'm struggling with adding 'raw pointers' as CComPtr in a std::vector, without memory leaks.
To illustrate:
- GetInputLayout returns a ID3D11InputLayout* (raw pointer)
- the mInputLayouts is a std::vector<CComPtr<ID3D11InputLayout>>
This code works without memory leaks from D3D (ref counts, no release() issues):
ID3D11InputLayout *newLayout = mFallbackPack.GetInputLayout(pDevice); mInputLayouts.emplace_back(); mInputLayouts.back() = newLayout; ReleaseCOM(newLayout);
When I do it 'directly', I get REF count issues with D3D (leaks):
mInputLayouts.push_back(mFallbackPack.GetInputLayout(pDevice));
I can explain that the 2nd option gives a leak, because I'm trying to add a RAW pointer in a std::vector with CComPtr's.
Question: is there an easier way to achieve what I want? (without 4 lines of code)
Any input/ thoughts are appreciated.