Crash of Directshow plugin with OpenCV when using cv::Mat

Hi, guys

I follow the tutorial to build a Directshow plugin with TemplateExtOpenCV, and everything is OK at the beginning. But when I create a cv::Mat instance and allocate memory for it, the application crashes at runtime and shows a dialog like this:

The debug log is

In __cxa_throw () (D:\vvvv\vvvv_45beta32.1_x86\lib\thirdparty\x86\opencv\libopencv_core241.dll)
In libstdc++-6!__cxa_throw () (D:\vvvv\vvvv_45beta32.1_x86\lib\thirdparty\x86\opencv\libstdc++-6.dll)
In libstdc++-6!__cxa_demangle () (D:\vvvv\vvvv_45beta32.1_x86\lib\thirdparty\x86\opencv\libstdc++-6.dll)
In libgcc_s_dw2-1!_Unwind_RaiseException () (D:\vvvv\vvvv_45beta32.1_x86\lib\thirdparty\x86\opencv\libgcc_s_dw2-1.dll)
In libgcc_s_dw2-1!_Unwind_FindEnclosingFunction () (D:\vvvv\vvvv_45beta32.1_x86\lib\thirdparty\x86\opencv\libgcc_s_dw2-1.dll)
In libgcc_s_dw2-1!_Unwind_Find_FDE () (D:\vvvv\vvvv_45beta32.1_x86\lib\thirdparty\x86\opencv\libgcc_s_dw2-1.dll)
In libgcc_s_dw2-1!_Unwind_Resume_or_Rethrow () (D:\vvvv\vvvv_45beta32.1_x86\lib\thirdparty\x86\opencv\libgcc_s_dw2-1.dll)
In libgcc_s_dw2-1!_Unwind_Find_FDE () (D:\vvvv\vvvv_45beta32.1_x86\lib\thirdparty\x86\opencv\libgcc_s_dw2-1.dll)
In libgcc_s_dw2-1!_Unwind_Resume_or_Rethrow () (D:\vvvv\vvvv_45beta32.1_x86\lib\thirdparty\x86\opencv\libgcc_s_dw2-1.dll)
In libgcc_s_dw2-1!__emutls_get_address () (D:\vvvv\vvvv_45beta32.1_x86\lib\thirdparty\x86\opencv\libgcc_s_dw2-1.dll)
In msvcrt!malloc () (C:\Windows\syswow64\msvcrt.dll)
In libgcc_s_dw2-1!_Unwind_Resume_or_Rethrow () (D:\vvvv\vvvv_45beta32.1_x86\lib\thirdparty\x86\opencv\libgcc_s_dw2-1.dll)
In libgcc_s_dw2-1!__emutls_get_address () (D:\vvvv\vvvv_45beta32.1_x86\lib\thirdparty\x86\opencv\libgcc_s_dw2-1.dll)
In msvcrt!malloc () (C:\Windows\syswow64\msvcrt.dll)
In libgcc_s_dw2-1!_Unwind_Resume_or_Rethrow () (D:\vvvv\vvvv_45beta32.1_x86\lib\thirdparty\x86\opencv\libgcc_s_dw2-1.dll)
In libgcc_s_dw2-1!__emutls_get_address () (D:\vvvv\vvvv_45beta32.1_x86\lib\thirdparty\x86\opencv\libgcc_s_dw2-1.dll)
In msvcrt!free () (C:\Windows\syswow64\msvcrt.dll)
In msvcrt!memset () (C:\Windows\syswow64\msvcrt.dll)
In msvcrt!free () (C:\Windows\syswow64\msvcrt.dll)
In ntdll!LdrWx86FormatVirtualImage () (C:\Windows\system32\ntdll.dll)
In ntdll!RtlEncodePointer () (C:\Windows\system32\ntdll.dll)
In ntdll!LdrWx86FormatVirtualImage () (C:\Windows\system32\ntdll.dll)
In ntdll!RtlEncodePointer () (C:\Windows\system32\ntdll.dll)
In ntdll!TpDbgDumpHeapUsage () (C:\Windows\system32\ntdll.dll)
In ntdll!RtlReAllocateHeap () (C:\Windows\system32\ntdll.dll)
In ntdll!TpQueryPoolStackInformation () (C:\Windows\system32\ntdll.dll)
In ntdll!LdrWx86FormatVirtualImage () (C:\Windows\system32\ntdll.dll)
In ntdll!TpQueryPoolStackInformation () (C:\Windows\system32\ntdll.dll)
In ntdll!RtlInitializeContext () (C:\Windows\system32\ntdll.dll)
In ntdll!TpQueryPoolStackInformation () (C:\Windows\system32\ntdll.dll)
In ntdll!LdrQueryProcessModuleInformation () (C:\Windows\system32\ntdll.dll)
In ntdll!TpQueryPoolStackInformation () (C:\Windows\system32\ntdll.dll)
In ntdll!TpReleaseTimer () (C:\Windows\system32\ntdll.dll)
In ntdll!LdrAddRefDll () (C:\Windows\system32\ntdll.dll)
In ntdll!TpReleaseTimer () (C:\Windows\system32\ntdll.dll)
In ntdll!TpDbgSetLogRoutine () (C:\Windows\system32\ntdll.dll)
In ntdll!TpQueryPoolStackInformation () (C:\Windows\system32\ntdll.dll)
In ntdll!RtlNtStatusToDosError () (C:\Windows\system32\ntdll.dll)
In wcspbrk () (C:\Windows\system32\ntdll.dll)
In ntdll!DbgUiStopDebugging () (C:\Windows\system32\ntdll.dll)
In ntdll!RtlInitializeExceptionChain () (C:\Windows\system32\ntdll.dll)
In ntdll!RtlpConvertCultureNamesToLCIDs () (C:\Windows\system32\ntdll.dll)
In wcspbrk () (C:\Windows\system32\ntdll.dll)
In ntdll!RtlpConvertCultureNamesToLCIDs () (C:\Windows\system32\ntdll.dll)
In ntdll!RtlFillMemory () (C:\Windows\system32\ntdll.dll)
In ntdll!RtlFillMemoryUlong () (C:\Windows\system32\ntdll.dll)
In towlower () (C:\Windows\system32\ntdll.dll)
In ntdll!RtlContractHashTable () (C:\Windows\system32\ntdll.dll)
In ntdll!RtlFillMemoryUlong () (C:\Windows\system32\ntdll.dll)
In ntdll!RtlSetCurrentTransaction () (C:\Windows\system32\ntdll.dll)
In wcspbrk () (C:\Windows\system32\ntdll.dll)
In ntdll!AlpcMaxAllowedMessageLength () (C:\Windows\system32\ntdll.dll)
In wcspbrk () (C:\Windows\system32\ntdll.dll)
In ntdll!TpQueryPoolStackInformation () (C:\Windows\system32\ntdll.dll)
In ntdll!RtlSecondsSince1980ToTime () (C:\Windows\system32\ntdll.dll)
In ntdll!TpQueryPoolStackInformation () (C:\Windows\system32\ntdll.dll)
In ntdll!RtlValidateHeap () (C:\Windows\system32\ntdll.dll)
In ntdll!LdrWx86FormatVirtualImage () (C:\Windows\system32\ntdll.dll)
In ntdll!RtlEncodePointer () (C:\Windows\system32\ntdll.dll)
In ntdll!LdrWx86FormatVirtualImage () (C:\Windows\system32\ntdll.dll)
In ntdll!RtlEncodePointer () (C:\Windows\system32\ntdll.dll)
In ntdll!TpDbgDumpHeapUsage () (C:\Windows\system32\ntdll.dll)
In ntdll!RtlReAllocateHeap () (C:\Windows\system32\ntdll.dll)
In ntdll!RtlEncodePointer () (C:\Windows\system32\ntdll.dll)
In ntdll!RtlInitializeContext () (C:\Windows\system32\ntdll.dll)
In ntdll!RtlUpcaseUnicodeChar () (C:\Windows\system32\ntdll.dll)

And also the system log:

- <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
- <System>
  <Provider Name="Application Error" /> 
  <EventID Qualifiers="0">1000</EventID> 
  <Level>2</Level> 
  <Task>100</Task> 
  <Keywords>0x80000000000000</Keywords> 
  <TimeCreated SystemTime="2014-07-18T03:33:25.000000000Z" /> 
  <EventRecordID>56082</EventRecordID> 
  <Channel>Application</Channel> 
  <Security /> 
  </System>
- <EventData>
  <Data>vvvv.exe</Data> 
  <Data>32.1.292.0</Data> 
  <Data>5399d7d4</Data> 
  <Data>libstdc++-6.dll</Data> 
  <Data>0.0.0.0</Data> 
  <Data>4bc96cae</Data> 
  <Data>40000015</Data> 
  <Data>0001bd1d</Data> 
  <Data>1e48</Data> 
  <Data>01cfa23903f8218c</Data> 
  <Data>D:\vvvv\vvvv_45beta32.1_x86\vvvv.exe</Data> 
  <Data>D:\vvvv\vvvv_45beta32.1_x86\lib\thirdparty\x86\opencv\libstdc++-6.dll</Data> 
  <Data>463096d0-0e2c-11e4-a5e3-08002700c447</Data> 
  </EventData>
  </Event>

Any solution?

Maybe rebuild the dynamic libraries in VVVV_ROOT\lib\thirdparty\x86\opencv ?

so if you say you get the example to build but it fails as soon as you add your code i’d suggest your code to be the culprit.

you may also want to have a look at vvvv.packs.image which is the more modern way of using opencv code with vvvv.

hi, joreg, thanks for your reply

1 It should not be that my code has problem, because it’s just a single line such as

cv::Mat a(3, 3, CV_8UC1);

2 Mmm, the big problem is that I’m not familiar with C#

  1. well if the template works i am afraid i won’t be able to help you further
  2. if you’re familiar with c++ it should be a breeze and delight for you to get into c#

Do you use visual studio to build the plugin? if yes, the compiler version can create that problem. Also there can be issues with memory allocation constraints between debug and release builds.

Generally one easy way to avoid that, is to link against opencv static libs instead of the dynamic libs. That way you get a self contained dll which doesn’t needs megs and megs of externals (and avoid this compiler version issue).

joreg, thank you all the same.

hi, vux
I use code::blocks with MinGW GCC compiler just as the tutorial suggests.
I will try your solution later. For now, I use CvMat instead of cv::Mat, and it works.
Thanks for your help.