frontend-tools: Fix crash when adding invalid regex
When adding a new regex rule to the Automatic Scene Switcher, OBS would crash if the regex was invalid. This was because the regex was added to the Regex object without a test or try-catch. This commit fixes that behavior, and adds a warning message when attempting to add an invalid regex.
This commit is contained in:
parent
580cfc1a95
commit
91b64657c6
@ -3,6 +3,7 @@
|
||||
#include <obs.hpp>
|
||||
#include <util/util.hpp>
|
||||
#include <QMainWindow>
|
||||
#include <QMessageBox>
|
||||
#include <QAction>
|
||||
#include "auto-scene-switcher.hpp"
|
||||
|
||||
@ -231,13 +232,19 @@ void SceneSwitcher::on_add_clicked()
|
||||
int idx = FindByData(windowName);
|
||||
|
||||
if (idx == -1) {
|
||||
QListWidgetItem *item = new QListWidgetItem(text,
|
||||
ui->switches);
|
||||
item->setData(Qt::UserRole, v);
|
||||
|
||||
lock_guard<mutex> lock(switcher->m);
|
||||
switcher->switches.emplace_back(source,
|
||||
windowName.toUtf8().constData());
|
||||
try {
|
||||
lock_guard<mutex> lock(switcher->m);
|
||||
switcher->switches.emplace_back(source,
|
||||
windowName.toUtf8().constData());
|
||||
|
||||
QListWidgetItem *item = new QListWidgetItem(text,
|
||||
ui->switches);
|
||||
item->setData(Qt::UserRole, v);
|
||||
} catch (const regex_error &) {
|
||||
QMessageBox::warning(this,
|
||||
obs_module_text("InvalidRegex.Title"),
|
||||
obs_module_text("InvalidRegex.Text"));
|
||||
}
|
||||
} else {
|
||||
QListWidgetItem *item = ui->switches->item(idx);
|
||||
item->setText(text);
|
||||
|
@ -4,6 +4,8 @@ SceneSwitcher.OnNoMatch.DontSwitch="Don't switch"
|
||||
SceneSwitcher.OnNoMatch.SwitchTo="Switch to:"
|
||||
SceneSwitcher.CheckInterval="Check active window title every:"
|
||||
SceneSwitcher.ActiveOrNotActive="Scene Switcher is:"
|
||||
InvalidRegex.Title="Invalid Regular Expression"
|
||||
InvalidRegex.Text="The regular expression that you entered is invalid."
|
||||
Active="Active"
|
||||
Inactive="Inactive"
|
||||
Start="Start"
|
||||
|
Loading…
x
Reference in New Issue
Block a user