Procházet zdrojové kódy

virtualcam-module: Only allow DLL unload when filter freed

Fixes a bug where the DLL could unload while the filter is currently
being destroyed, which would cause a crash in the host process
jp9000 před 3 roky
rodič
revize
5efb3ea42d

+ 4 - 0
plugins/win-dshow/virtualcam-module/virtualcam-filter.cpp

@@ -10,6 +10,7 @@ using namespace DShow;
 extern bool initialize_placeholder();
 extern const uint8_t *get_placeholder_ptr();
 extern const bool get_placeholder_size(int *out_cx, int *out_cy);
+extern volatile long locks;
 
 /* ========================================================================= */
 
@@ -107,6 +108,7 @@ VCamFilter::VCamFilter()
 	th = std::thread([this] { Thread(); });
 
 	AddRef();
+	InterlockedIncrement(&locks);
 }
 
 VCamFilter::~VCamFilter()
@@ -118,6 +120,8 @@ VCamFilter::~VCamFilter()
 
 	if (placeholder.scaled_data)
 		free(placeholder.scaled_data);
+
+	InterlockedDecrement(&locks);
 }
 
 const wchar_t *VCamFilter::FilterName() const

+ 1 - 1
plugins/win-dshow/virtualcam-module/virtualcam-module.cpp

@@ -11,7 +11,7 @@ static const REGFILTERPINS AMSPinVideo = {L"Output", false, true,
 					  nullptr,   1,     &AMSMediaTypesV};
 
 HINSTANCE dll_inst = nullptr;
-static volatile long locks = 0;
+volatile long locks = 0;
 
 /* ========================================================================= */