Browse Source

obs-qsv11: Fix crash in QSV test process

The code assumed MFXCreateSession would always succeed, but it fails on
systems with no QSV implementations, causing a crash when we call
MFXClose later. Additional success checks for the other API calls were
also added.
Richard Stanway 2 years ago
parent
commit
609b1ab011
1 changed files with 10 additions and 2 deletions
  1. 10 2
      plugins/obs-qsv11/obs-qsv-test/obs-qsv-test.cpp

+ 10 - 2
plugins/obs-qsv11/obs-qsv-test/obs-qsv-test.cpp

@@ -162,7 +162,13 @@ try {
 		throw "CreateDXGIFactory1 failed";
 
 	mfxLoader loader = MFXLoad();
+	if (!loader)
+		throw "MFXLoad failed";
+
 	mfxConfig cfg = MFXCreateConfig(loader);
+	if (!cfg)
+		throw "MFXCreateConfig failed";
+
 	mfxVariant impl;
 
 	// Low latency is disabled due to encoding capabilities not being provided before TGL for VPL
@@ -171,14 +177,16 @@ try {
 	MFXSetConfigFilterProperty(
 		cfg, (const mfxU8 *)"mfxImplDescription.Impl", impl);
 
-	mfxSession m_session;
+	mfxSession m_session = nullptr;
 	mfxStatus sts = MFXCreateSession(loader, 0, &m_session);
 
 	uint32_t idx = 0;
 	while (get_adapter_caps(factory, loader, m_session, idx++) == true)
 		;
 
-	MFXClose(m_session);
+	if (m_session)
+		MFXClose(m_session);
+
 	MFXUnload(loader);
 
 	for (auto &[idx, caps] : adapter_info) {