简体   繁体   中英

Directshow render filter crashes only in release mode

I've written a custom renderer filter to push video frames to system memory and later to OpenGL. It's not in a DLL and I don't register it, but instead use it like this page describes in the first paragraph. This works fine in the Debug mode, but in Release it starts crashing. I'm doing the following to initialize the graph:

HRESULT hr;

CoInitialize(0);
CoCreateInstance(CLSID_FilterGraph, 0, CLSCTX_INPROC, IID_IGraphBuilder, (void**)&graph);

graph->QueryInterface(IID_IMediaControl, (void**)&mediaControl);
graph->QueryInterface(IID_IMediaSeeking, (void**)&mediaSeeking);

grabber = new textureGrabber(0, &hr);
grabber->AddRef(); // crash here
grabber->setTexture(&texture);
grabber->QueryInterface(IID_IBaseFilter, (void**)&base);

graph->AddFilter(base, L"OpenGL texture video filter");
graph->RenderFile(path.c_str(), 0);

This crashes on the AddRef() due to an access violation. I've already tried implementing the IUnknown of the class myself, and the best I got was to the AddFilter where it crashed because the IBaseFilter seemed to be invalid. After that I found even a Microsoft-issued example doing this the simple way and it seems to work for them. I'm curious what might be wrong since I'm doing the same exact thing - even tried the smart pointers.

EDIT: The problem is in the CBaseFilter DECLARE_IUNKNOWN macro, the GetOwner()->AddRef fails. GetOwner itself seems to work.

GetOwner returns whatever you pass as the second parameter to the CBaseFilter constructor. Normally NULL unless you are aggregating the object for some reason (if you are, you probably don't need to).

A crash can occur at that point if your release build is linking against Strmbasd.lib , which is the debug version of the DirectShow base class library.

Change your project's release configuration to link against Strmbase.lib instead, which is the release version of the library.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM