Fix crash when Grok is enabled but no gpu_lister is available.
authorCarl Hetherington <cth@carlh.net>
Sat, 29 Mar 2025 20:38:27 +0000 (21:38 +0100)
committerCarl Hetherington <cth@carlh.net>
Sat, 29 Mar 2025 20:38:27 +0000 (21:38 +0100)
src/lib/grok/util.cc

index 3cbc55678102cf27decc3165f87c0f3dca18bfab..51b9c1037b5b643d14ae7196fffcad925ce86d78 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "util.h"
 #include "../config.h"
+#include "../dcpomatic_log.h"
 #include <boost/process.hpp>
 #include <future>
 
@@ -37,17 +38,23 @@ get_gpu_names()
        auto binary = Config::instance()->grok().binary_location / "gpu_lister";
 
        bp::ipstream stream;
-       bp::child child(binary, bp::std_out > stream);
 
-       string line;
-       vector<string> gpu_names;
-       while (child.running() && std::getline(stream, line) && !line.empty()) {
-               gpu_names.push_back(line);
-       }
+       try {
+               bp::child child(binary, bp::std_out > stream);
+
+               string line;
+               vector<string> gpu_names;
+               while (child.running() && std::getline(stream, line) && !line.empty()) {
+                       gpu_names.push_back(line);
+               }
 
-       child.wait();
+               child.wait();
 
-       return gpu_names;
+               return gpu_names;
+       } catch (std::exception& e) {
+               LOG_ERROR("Could not fetch GPU names: %1", e.what());
+               return {};
+       }
 }