Re: Global CComPtr
- From: "Thore B. Karlsen [DShow MVP]" <sid@xxxxxxxx>
- Date: Fri, 15 Sep 2006 14:01:38 -0500
On 15 Sep 2006 11:39:48 -0700, "Walter" <waltshirey@xxxxxxxxx> wrote:
Here is where I build my graph:
// Create the Filter Graph Manager (FGM)
hr = pSourceGraph.CoCreateInstance(CLSID_FilterGraph);
// Obtain the interface used to run, stop, and pause the graph
hr = pSourceGraph->QueryInterface(IID_IMediaControl, (void
**)&pMediaControl);
// Obtain the interface to receive events from the graph
hr = pSourceGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);
You might want to use CComQIPtr instead of QueryInterface. It's
cleaner and safer.
[...]
pEnum.Release();
*ppPin = pPin;
return S_OK;
You have a problem here, because you are assigning pPin directly to
ppPin without adding a reference to it. pPin will be released when you
return, which will leave ppPin invalid. Try doing an AddRef() before
you return.
I thought you couldn't use AddRef() with a CComPtr. At least that's
what my compiler is telling me.
Call AddRef() on ppPin after you assign to it.
I'm still getting an error after releasing all my smart pointers. The
error occurs when calling pSourceGraph.Release(). Is there any way to
find what's keeping that from releasing?
I didn't see anything else wrong in the code you posted, so I suspect
the problem is that you're not calling AddRef above. When you release
your graph, all the filters are going to be released, and the pins
owned by the filters are going to be released. The problem is that
some of them will already have a refcount of 0 and will be deleted
because they didn't have the correct refcount.
Take e.g. your pCapturePin. Here is the problem:
1. You create your capture filter. It creates its pins, so the pins
have a refcount of 1.
2. You find the output pin in your function above. It's assigned to
pPin in pEnum->Next(). Next() will increase the refcount, so the pin
will now have a refcount of 2. You assign the pin to ppPin, which is a
pointer to a raw pointer. The pin still has a reference count of 2.
3. You return from your function, and pPin goes out of scope. This
decreases the refcount to 1. pCapturePin is now wrapping the pointer
you assigned to ppPin.
4. In your cleanup, you release pCapturePin, bringing the refcount to
0 and causing the pin to be deleted. This is a problem because the
capture filter is still alive in the graph, and the filter still
thinks the pin is alive.
5. When you release the graph, the graph will release its filters, and
the capture filter will release its pins. Since one of the pins is no
longer there, you get an error.
--
Be seeing you.
.
- Follow-Ups:
- Re: Global CComPtr
- From: Walter
- Re: Global CComPtr
- References:
- Global CComPtr
- From: Walter
- Re: Global CComPtr
- From: The March Hare [MVP]
- Re: Global CComPtr
- From: Walter
- Re: Global CComPtr
- From: Thore B. Karlsen [DShow MVP]
- Re: Global CComPtr
- From: Walter
- Re: Global CComPtr
- From: Thore B. Karlsen [DShow MVP]
- Re: Global CComPtr
- From: Walter
- Re: Global CComPtr
- From: Thore B. Karlsen [DShow MVP]
- Re: Global CComPtr
- From: Walter
- Global CComPtr
- Prev by Date: Re: Global CComPtr
- Next by Date: Re: Live Push Source Filter must support IAMPushSource?
- Previous by thread: Re: Global CComPtr
- Next by thread: Re: Global CComPtr
- Index(es):
Relevant Pages
|