videoInput
videoInput copied to clipboard
CoInitialize/CoUninitialize will be unbalanced if app under single threaded COM
At the videoInput::comInit, https://github.com/ofTheo/videoInput/blob/master/videoInputSrcAndDemos/libs/videoInput/videoInput.cpp#L1451
comUnInit()
does not check whether the previous CoInitializeEx
call in comInit()
is failed or succeeded to call CoUninitialize
. If the CoInitializeEx
is failed because thread mode change, its internal reference count will not be added. Then still calling the CoUninitialize
would cause the the CoInitialize/CoUninitialize
unbalanced. Currently, it only send the warning as react.
See the remark of CoInitializeEx.
To close the COM library gracefully on a thread, each successful call to CoInitialize or CoInitializeEx, including any call that returns S_FALSE, must be balanced by a corresponding call to CoUninitialize.
In my project (under single threaded com), I met a bug that my internal COM dll is always unloaded too early only on Windows 7 x86 (still don't know why it only happen on win7). I used the IInitializeSpy to monitor the changes of reference count of CoInitialize
. I notices the reference count is always dropped by 1 if one of my module using opencv library was loaded by LoadLibrary
.
Issue is gone after I unlink the highgui.dll from my project.