diff --git a/code/components/jomjol_flowcontroll/ClassFlowControll.cpp b/code/components/jomjol_flowcontroll/ClassFlowControll.cpp index 6549c89a..b2cefbd5 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowControll.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowControll.cpp @@ -34,7 +34,9 @@ static const char* TAG = "FLOW CTRL"; std::string ClassFlowControll::doSingleStep(std::string _stepname, std::string _host){ std::string _classname = ""; std::string result = ""; -// ESP_LOGD(TAG, "_stepname: %s", _stepname.c_str()); + + ESP_LOGD(TAG, "Step %s start", _stepname.c_str()); + if ((_stepname.compare("[MakeImage]") == 0) || (_stepname.compare(";[MakeImage]") == 0)){ _classname = "ClassFlowMakeImage"; } @@ -61,6 +63,8 @@ std::string ClassFlowControll::doSingleStep(std::string _stepname, std::string _ result = FlowControll[i]->getHTMLSingleStep(_host); } + ESP_LOGD(TAG, "Step %s end", _stepname.c_str()); + return result; } diff --git a/code/components/jomjol_helper/Helper.cpp b/code/components/jomjol_helper/Helper.cpp index b7a2499e..00561c46 100644 --- a/code/components/jomjol_helper/Helper.cpp +++ b/code/components/jomjol_helper/Helper.cpp @@ -9,6 +9,8 @@ #include #include +#include +#include #ifdef __cplusplus extern "C" { @@ -194,6 +196,12 @@ std::string FormatFileName(std::string input) } +std::size_t file_size(const std::string& file_name) { + std::ifstream file(file_name.c_str(),std::ios::in | std::ios::binary); + if (!file) return 0; + file.seekg (0, std::ios::end); + return static_cast(file.tellg()); +} void FindReplace(std::string& line, std::string& oldString, std::string& newString) { diff --git a/code/components/jomjol_helper/Helper.h b/code/components/jomjol_helper/Helper.h index 21170a9e..1aa39904 100644 --- a/code/components/jomjol_helper/Helper.h +++ b/code/components/jomjol_helper/Helper.h @@ -7,6 +7,7 @@ using namespace std; std::string FormatFileName(std::string input); +std::size_t file_size(const std::string& file_name); void FindReplace(std::string& line, std::string& oldString, std::string& newString); bool CopyFile(string input, string output); diff --git a/code/components/jomjol_image_proc/CFindTemplate.cpp b/code/components/jomjol_image_proc/CFindTemplate.cpp index c12792c7..f77ec19f 100644 --- a/code/components/jomjol_image_proc/CFindTemplate.cpp +++ b/code/components/jomjol_image_proc/CFindTemplate.cpp @@ -1,6 +1,7 @@ #include "CFindTemplate.h" #include "ClassLogFile.h" +#include "Helper.h" #include @@ -11,7 +12,19 @@ static const char* TAG = "C FIND TEMPL"; bool CFindTemplate::FindTemplate(RefInfo *_ref) { - uint8_t* rgb_template = stbi_load(_ref->image_file.c_str(), &tpl_width, &tpl_height, &tpl_bpp, channels); + uint8_t* rgb_template; + + if (file_size(_ref->image_file.c_str()) == 0) { + LogFile.WriteToFile(ESP_LOG_ERROR, TAG, _ref->image_file + " is empty!"); + return false; + } + + rgb_template = stbi_load(_ref->image_file.c_str(), &tpl_width, &tpl_height, &tpl_bpp, channels); + + if (rgb_template == NULL) { + LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Failed to load " + _ref->image_file + "! Is it corrupted?"); + return false; + } // ESP_LOGD(TAG, "FindTemplate 01"); @@ -71,6 +84,9 @@ bool CFindTemplate::FindTemplate(RefInfo *_ref) #endif _ref->found_x = _ref->fastalg_x; _ref->found_y = _ref->fastalg_y; + + stbi_image_free(rgb_template); + return true; } diff --git a/code/components/jomjol_image_proc/CImageBasis.cpp b/code/components/jomjol_image_proc/CImageBasis.cpp index 334fecc7..7a1e19f3 100644 --- a/code/components/jomjol_image_proc/CImageBasis.cpp +++ b/code/components/jomjol_image_proc/CImageBasis.cpp @@ -436,8 +436,20 @@ CImageBasis::CImageBasis(std::string _image) long zwld = esp_get_free_heap_size(); ESP_LOGD(TAG, "freeheapsize before: %ld", zwld); + if (file_size(_image.c_str()) == 0) { + LogFile.WriteToFile(ESP_LOG_ERROR, TAG, _image + " is empty!"); + return; + } + RGBImageLock(); rgb_image = stbi_load(_image.c_str(), &width, &height, &bpp, channels); + + if (rgb_image == NULL) { + LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Failed to load " + _image + "! Is it corrupted?"); + RGBImageRelease(); + return; + } + RGBImageRelease(); zwld = esp_get_free_heap_size();