0

I have a problem with CoCreateInstance which doesn't ever return after being called. Its called from a overriden method of CSourceStream::OnThreadCreate

I think the problem is that I try to use COM inside a seperate thread but I am not sure. How do I use COM inside another thread? Here is the call stack and how I call the function anyways. I checked that CoInitialiseEx returns S_FALSE, so com is running on that thread. Call Stack

HRESULT hr = CoCreateInstance(CLSID_FilterGraph, NULL,
        CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pGraph));

I found out that if I use CoCreateInstance in another method(CSourceStream::FillBuffer) that runs on the same thread it works but I don't know why.

When CoCreateInstance hangs, its stuck on WaitForMultipleObjectsEx, like so: Call stack 2

Lenart12
  • 21
  • 4
  • My crystal ball says you didn't call `CoInitializeEx` on that thread. – paddy Apr 12 '21 at 08:01
  • Not to be rude, but did you read my question? I did call CoInitializeEx and it returns S_FALSE - (from msdn S_FALSE = The COM library is already initialized on this thread.). – Lenart12 Apr 12 '21 at 08:07
  • More info here: [How to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) – paddy Apr 12 '21 at 08:13
  • 1
    This is probably not a COM issue by itself. Read Filter Graph Manager's doc carefully, https://learn.microsoft.com/en-us/windows/win32/directshow/filter-graph-manager it has some threading subtleties. COM is running, but maybe not the way it should. – Simon Mourier Apr 12 '21 at 08:40

1 Answers1

0

Like Simon said in the comments, changing CLSID_FilterGraph to CLSID_FilterGraphNoThread removed the deadlock.

Lenart12
  • 21
  • 4