Original Post
Hi,
I have modified the PushSource Desktop filter for my own purpose (converting an offscreen rendered D3D surface into a video stream). Therefore I added an interface to my filter so I can pass it a pointer to my IDirect3DSurface9. By the point, it works "fine", since it correctly shows me the surface as a video stream. But when I close my test application I get a "2 objects left active!" error, here the complete error message:
"Executable: PSD3DFilterTest.exe Pid e08 Tid ef0. Module PushSourceD3D.dll, 2 objects left active!
At line 317 of C:\DX90SDK\Samples\C++\DirectShow\BaseClasses\dllentry.cpp"
This error appeared first when I introduce my ID3DSurf interface, but don''t know what I''ve forgotten.
I render the out pin of my filter using RenderEx(pOutputPin, AM_RENDEREX_RENDERTOEXISTINGRENDERERS, NULL). Where can be my problem?
Thanks in advance..
Here the main parts of my CPushSourceD3D class:
//////////////////////////////////////
//A part of my PushSourceD3D.hpp file
//////////////////////////////////////
class CPushSourceD3D : public CSource, public ID3DSurf
{
friend class CPushPinD3D;
private:
// Constructor is private because you have to use CreateInstance
CPushSourceD3D(IUnknown *pUnk, HRESULT *phr);
~CPushSourceD3D();
CPushPinD3D *m_pPin;
//ID3DSurf interface
CCritSec m_csShared; //Protects shared data
LPDIRECT3DSURFACE9 m_pD3DSurface; //D3D Source Surface
public:
static CUnknown * WINAPI CreateInstance(IUnknown *pUnk, HRESULT *phr);
// Reveals ID3DSurf
STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void ** ppv);
DECLARE_IUNKNOWN;
//Get the current surface pointed by the ID3DSurf interface
STDMETHODIMP get_D3DSurface(LPDIRECT3DSURFACE9 *pD3DSurface9)
{
if (!pD3DSurface9) return E_POINTER;
CAutoLock lock(&m_csShared);
*pD3DSurface9 = m_pD3DSurface;
//MessageBox(NULL, TEXT("get_D3DSurface"), TEXT("Surface returned"), MB_OK);
return S_OK;
}
//Set the surface to be pointed by the ID3DSurf interface
STDMETHODIMP set_D3DSurface(LPDIRECT3DSURFACE9 pD3DSurface9)
{
if (!pD3DSurface9) return E_POINTER;
CAutoLock lock(&m_csShared);
m_pD3DSurface = pD3DSurface9;
//MessageBox(NULL, TEXT("select_D3DSurface"), TEXT("Surface set"), MB_OK);
return S_OK;
}
};
//////////////////////////////////////
//A part of my PushSourceD3D.cpp file
//////////////////////////////////////
/**********************************************
*
* CPushSourceD3D Class
*
**********************************************/
CPushSourceD3D::CPushSourceD3D(IUnknown *pUnk, HRESULT *phr)
: CSource(NAME("PushSourceD3D"), pUnk, CLSID_PushSourceD3D)
{
// The pin magically adds itself to our pin array.
m_pPin = new CPushPinD3D(phr, this);
m_pD3DSurface = NULL;
if (phr)
{
if (m_pPin == NULL)
*phr = E_OUTOFMEMORY;
else
*phr = S_OK;
}
}
CPushSourceD3D::~CPushSourceD3D()
{
delete m_pPin;
m_pD3DSurface = NULL;
}
CUnknown * WINAPI CPushSourceD3D::CreateInstance(IUnknown *pUnk, HRESULT *phr)
{
CPushSourceD3D *pNewFilter = new CPushSourceD3D(pUnk, phr );
if (phr)
{
if (pNewFilter == NULL)
*phr = E_OUTOFMEMORY;
else
*phr = S_OK;
}
return pNewFilter;
}
//
// NonDelegatingQueryInterface
//
// Reveals ID3DSurf interface
//
STDMETHODIMP CPushSourceD3D::NonDelegatingQueryInterface(REFIID riid, void **ppv)
{
CheckPointer(ppv,E_POINTER);
if (riid == IID_ID3DSurf) {
//return GetInterface((ID3DSurf *) this, ppv);
return GetInterface(static_cast<ID3DSurf*>(this), ppv);
} else {
return CSource::NonDelegatingQueryInterface(riid, ppv);
}
} // NonDelegatingQueryInterface