From 57c698ffd9afeeda1fe7240f98549ab24a3302fa Mon Sep 17 00:00:00 2001 From: WarmUpTill <19472752+WarmUpTill@users.noreply.github.com> Date: Thu, 28 May 2026 16:33:09 +0200 Subject: [PATCH] Fix freeze when choosing invalid OCR model --- plugins/video/macro-condition-video.cpp | 5 +++-- plugins/video/parameter-wrappers.cpp | 23 +++++++++++++---------- plugins/video/parameter-wrappers.hpp | 5 +---- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/plugins/video/macro-condition-video.cpp b/plugins/video/macro-condition-video.cpp index bdf4566b..1e3ee09b 100644 --- a/plugins/video/macro-condition-video.cpp +++ b/plugins/video/macro-condition-video.cpp @@ -403,11 +403,12 @@ bool MacroConditionVideo::CheckBrightnessThreshold() bool MacroConditionVideo::CheckOCR() { - if (!_ocrParameters.Initialized()) { + auto *ocr = _ocrParameters.GetOCR(); + if (!ocr) { return false; } - auto text = RunOCR(_ocrParameters.GetOCR(), _screenshotData.GetImage(), + auto text = RunOCR(ocr, _screenshotData.GetImage(), _ocrParameters.color, _ocrParameters.colorThreshold); if (!text) { return false; diff --git a/plugins/video/parameter-wrappers.cpp b/plugins/video/parameter-wrappers.cpp index c3e0f7fe..3d988c37 100644 --- a/plugins/video/parameter-wrappers.cpp +++ b/plugins/video/parameter-wrappers.cpp @@ -318,9 +318,6 @@ OCRParameters::OCRParameters(const OCRParameters &other) useConfig(other.useConfig), configFile(other.configFile) { - if (!initDone) { - Setup(); - } } OCRParameters &OCRParameters::operator=(const OCRParameters &other) @@ -334,9 +331,7 @@ OCRParameters &OCRParameters::operator=(const OCRParameters &other) languageCode = other.languageCode; useConfig = other.useConfig; configFile = other.configFile; - if (!initDone) { - Setup(); - } + initDone = false; return *this; } @@ -412,6 +407,14 @@ void OCRParameters::SetPageMode(tesseract::PageSegMode mode) } } +tesseract::TessBaseAPI *OCRParameters::GetOCR() +{ + if (!initDone) { + Setup(); + } + return initDone ? ocr.get() : nullptr; +} + bool OCRParameters::SetLanguageCode(const std::string &value) { const auto dataPath = QString::fromStdString(tesseractBasePath) + "/" + @@ -421,7 +424,7 @@ bool OCRParameters::SetLanguageCode(const std::string &value) return false; } languageCode = value; - Setup(); + initDone = false; return true; } @@ -440,7 +443,7 @@ bool OCRParameters::SetTesseractBasePath(const std::string &value) return false; } tesseractBasePath = value; - Setup(); + initDone = false; return true; } @@ -452,13 +455,13 @@ std::string OCRParameters::GetTesseractBasePath() const void OCRParameters::EnableCustomConfig(bool enable) { useConfig = enable; - Setup(); + initDone = false; } void OCRParameters::SetCustomConfigFile(const std::string &filename) { configFile = filename; - Setup(); + initDone = false; } void OCRParameters::Setup() diff --git a/plugins/video/parameter-wrappers.hpp b/plugins/video/parameter-wrappers.hpp index 04ad2dc2..60e3ecad 100644 --- a/plugins/video/parameter-wrappers.hpp +++ b/plugins/video/parameter-wrappers.hpp @@ -108,10 +108,7 @@ public: void SetCustomConfigFile(const std::string &); std::string GetCustomConfigFile() const { return configFile; } tesseract::PageSegMode GetPageMode() const { return pageSegMode; } - tesseract::TessBaseAPI *GetOCR() const - { - return initDone ? ocr.get() : nullptr; - } + tesseract::TessBaseAPI *GetOCR(); StringVariable text = obs_module_text("AdvSceneSwitcher.enterText"); RegexConfig regex = RegexConfig::PartialMatchRegexConfig();