【发布时间】:2019-04-03 21:07:07
【问题描述】:
在没有实际问题的情况下加载纹理,我用来临时获取 D3D11_TEXTURE2D_DESC 信息的 ID3D11Texture2D 似乎没有正确删除。
如果我不费心使用 ID3D11Texture2D 项目,我就没有内存泄漏。当我使用它时,尽管在得到我需要的东西后将其删除,但在使用 ReportLiveObjects 函数时它会在关机时留下。
我尝试使用自己的 * 并手动删除它,我尝试使用 ComPtr 并尝试各种方法来释放其中一个。
Microsoft::WRL::ComPtr<ID3D11Texture2D> pTextureInterface = nullptr;
ID3D11Resource *res = nullptr;
HRESULT hres = DirectX::CreateWICTextureFromFileEx(m_pDev, const_cast<wchar_t*>(wStrAddress.c_str()), 0, D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0, DirectX::WIC_LOADER_IGNORE_SRGB, &res, tempTex.ReleaseAndGetAddressOf());
tempTex->GetResource(&res);
res->QueryInterface<ID3D11Texture2D>(&pTextureInterface);
D3D11_TEXTURE2D_DESC desc;
pTextureInterface->GetDesc(&desc);
RECT r;
r.left = 0;
r.top = 0;
r.right = desc.Width;
r.bottom = desc.Height;
if (pTextureInterface != nullptr)
{
pTextureInterface.ReleaseAndGetAddressOf();
pTextureInterface = nullptr;
}
if (res != nullptr)
{
res->Release();
res = nullptr;
}
当我创建和使用 pTextureInterface 时,我会收到 DirectX 内存泄漏警告,因为我加载的每个纹理的 Refcount 为 1。 如果我根本不费心使用 pTextureInterface 我没有泄漏并且所有内容都可以正确加载和显示(除了它们的尺寸,因为我随后手动设置源图像的矩形边界)
我意识到这可能是一些小小的疏忽,但我一整天都找不到有效的解决方案,我们将不胜感激。
【问题讨论】:
标签: c++ memory-leaks textures loading directx-11