Fixed check for non-existing module

This commit is contained in:
Bob Polis 2021-10-07 12:42:13 +02:00
parent 90e19e3211
commit f33818d4ca

View File

@ -14,6 +14,7 @@
#include <cmath>
#include <thread>
#include <fstream>
#include <algorithm>
// POSIX
#include <getopt.h>
@ -130,10 +131,10 @@ int main(int argc, const char * argv[]) {
throw std::runtime_error("unrecognized option");
}
}
std::vector<std::string> names {sc::plugin<ScreensaverPlugin>::names()};
if (optind == argc) {
// here when no file args
if (random_saver) {
std::vector<std::string> names {sc::plugin<ScreensaverPlugin>::names()};
saver_name = sc::random::choice(names);
} else {
saver_name = "Default";
@ -146,6 +147,11 @@ int main(int argc, const char * argv[]) {
if (random_saver) {
std::cerr << "screensaver: warning: -r option overridden by file arg\n";
}
auto it = std::find(names.begin(), names.end(), saver_name);
if (it == names.end()) {
saver_name = "";
throw std::out_of_range(saver_name);
}
break; // only first one used
} catch (const std::runtime_error& ex) {
std::cerr << "screensaver: " << ex.what() << '\n';