From 672378d2027b0545007333971c0aafd520cfc6eb Mon Sep 17 00:00:00 2001 From: jp9000 Date: Wed, 16 Sep 2015 19:20:32 -0700 Subject: [PATCH] win-mf: Drain events before releasing encoder After I made it so that the encoder internal data gets destroyed when all outputs stop using it (fa7286f8), the media foundation h264 encoder started having crashes on shutdown. After a lot of testing, I realized that the reason it started happening is almost assuredly because active encoding events had not yet been completed. After making it wait on those events by calling DrainEvents(true), the crashes stopped. So asynchronous actions were clearly still occurring and it was shutting down while data was still being processed, thus leading to a crash. --- plugins/win-mf/mf-h264-encoder.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/win-mf/mf-h264-encoder.cpp b/plugins/win-mf/mf-h264-encoder.cpp index 3c929d852..6d18c35c7 100644 --- a/plugins/win-mf/mf-h264-encoder.cpp +++ b/plugins/win-mf/mf-h264-encoder.cpp @@ -70,7 +70,12 @@ H264Encoder::H264Encoder(const obs_encoder_t *encoder, {} H264Encoder::~H264Encoder() -{} +{ + // Make sure all events have finished before releasing. + // If you do not do this, you risk it releasing while there's still + // encoder activity, which can cause a crash with certain interfaces. + DrainEvent(true); +} HRESULT H264Encoder::CreateMediaTypes(ComPtr &i, ComPtr &o)