IDirect3DTexture9的DirectX9代理DLL

时间:2019-07-17 03:37:07

标签: proxy directx

我正在尝试在代理 IDirect3DDevice9 :: CreateTexture 中返回 IDirect3DTexture9 的自定义子类。 IDirect3DTexture9 的子类存储指向原始 IDirect3DTexture9 的指针,并将其代理到该函数。 当目标应用程序使用已子类化的纹理( DPX_IDirect3DTexture9 ),然后调用诸如 DrawIndexedPrimitive 之类的渲染函数时,它将因访问冲突而崩溃。

目标是完整跟踪设备资源的分配和释放,因此必须跟踪诸如 IDirect3DTexture9 :: Release 之类的方法。

我创建了一个类( DPX_IDirect3DTexture9 ),该类继承自 IDirect3DTexture9 ,该指针存储指向原始IDirect3DTexture9的指针,然后将其存储在子类 DPX_IDirect3DDevice9 ”中。 s的 CreateTexture 函数,我调用IDirect3DTexture9的原始CreateTexture,然后分配 DPX_IDirect3DTexture9 的实例(使用new)并传递原始指针。

class DPX_IDirect3DDevice9 : public IDirect3DDevice9
{
public:
    DPX_IDirect3DDevice9(IDirect3DDevice9* pOriginal) :
        m_pOriginal(pOriginal)
    {
    }    
    virtual ~DPX_IDirect3DDevice9() { }

    virtual HRESULT WINAPI CreateTexture(UINT Width, UINT Height, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DTexture9** ppTexture, HANDLE* pSharedHandle) override
    {
        HRESULT hr = m_pOriginal->CreateTexture(Width, Height, Levels, Usage, Format, Pool, ppTexture, pSharedHandle);
        if (FAILED(hr))
            return hr;

        *ppTexture = new DPX_IDirect3DTexture9(this, *ppTexture);
        return S_OK;
    }

    // ... omitted all other overridden functions as they're same style as above

private:
    IDirect3DDevice9* m_pOriginal;
};

class DPX_IDirect3DTexture9 : public IDirect3DTexture9
{
public:
    DPX_IDirect3DTexture9(DPX_IDirect3DDevice9* pOwner, IDirect3DTexture9* pOriginal, BOOL bRequiresRelease);
    virtual ~DPX_IDirect3DTexture9();

    virtual HRESULT              WINAPI QueryInterface(REFIID riid, void** ppvObj) override;
    // ... omitted overridden functions

    DPX_IDirect3DDevice9* m_pOwner;
    IDirect3DTexture9* m_pOriginal;
};

问题在于,当绘图调用使用先前通过IDirect3DDevice9 :: SetTexture设置的纹理时,崩溃。

0 个答案:

没有答案