将 DirectX 对象推入 std::queue

Pushing a DirectX object into a std::queue

我正在开发一个小型发布管理器,用于删除旧对象。

我正在使用 std::queue 来保存对象的年龄和指针。

这是我用来将值推入队列的方法:

ID3D12Resource* texture; // declaration
renderPlat->PushToReleaseManager(texture);

std::queue<std::pair<int,void*>> mResourceBin; // declaration
void RenderPlatform::PushToReleaseManager(ID3D12Resource* res)
{
    if (!res)
        return;
    mResourceBin.push(std::pair<int, void*>(0, res));
}

但这会导致 抛出异常:读取访问冲突 / std::_Deque_alloc<std::_Deque_base_types<std::pair<int,void * __ptr64>,std::allocator<std::pair<int,void * __ptr64> > > >::_Myoff(...) returned 0x6B0 :

void push_back(value_type&& _Val)
    {   // insert element at end
    this->_Orphan_all();
    _PUSH_BACK_BEGIN;  // <--- The exception is thrown here!!!
    this->_Getal().construct(
        _Unfancy(this->_Map()[_Block] + _Newoff % _DEQUESIZ),
        _STD forward<value_type>(_Val));
    _PUSH_BACK_END;
    }

我要删除的对象是 ID3D12Resource it inherits from IUnknown

编辑:

我正在使用:Visual Studio 2015 (v140).

编辑 2:

传递给 PushToReleaseManager() 的 ID3D12Resource* 对象是使用 ID3D12Device::CreateCommittedResource

创建的

尝试使用智能指针。它们比显式尝试释放内存要好得多。

我发现了问题。 我正在获取具有 PushToReleaseManager() 方法的 RenderPlatform,如下所示:

auto rPlat = (dx11on12::RenderPlatform*)(renderPlatform);

此转换失败,因为 renderPlatform 无效并且返回空指针。问题是我允许我毫无问题地调用该方法,我猜是因为它周围有一些垃圾内存。

感谢您的回答!