From 4dcd6c05a3a339102340d4dd20228c32b63b60e2 Mon Sep 17 00:00:00 2001 From: Maurice ONeal Date: Tue, 14 Feb 2023 19:29:02 -0500 Subject: [PATCH] v1.6.t7 the crashing issue might be the detection threads going out-of-scope before properly finishing. re-implemented share->detThreads from previous stable code to see if this fixes the issue. --- src/common.h | 2 +- src/main.cpp | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/common.h b/src/common.h index e10c01d..fdf73eb 100644 --- a/src/common.h +++ b/src/common.h @@ -37,7 +37,7 @@ using namespace cv; using namespace std; using namespace std::filesystem; -#define APP_VER "1.6.t6" +#define APP_VER "1.6.t7" #define APP_NAME "Motion Watch" #define TRIM_REMOVE " \n\r\t\f\v." diff --git a/src/main.cpp b/src/main.cpp index f14c49d..0b10333 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -96,7 +96,8 @@ void runTOCmds(int timeOut, const vector &cmds, vector &resLi res->cmd = cmd; res->finished = false; - res->ret = pthread_create(&res->thr, NULL, &runCmd, res); + + pthread_create(&res->thr, NULL, &runCmd, res); resList.push_back(res); } @@ -191,23 +192,25 @@ void recLoop(shared_t *share) runTOCmds(share->clipLen, cmds, rets); + for (auto &&ret : rets) + { + recLog("cmd: " + ret->cmd + " return_code: " + to_string(ret->ret), share); + } + if (allCmdsDidNotFail(rets)) { - new thread(detectMoInFile, detPath, recPath, share); + share->detThreads.push_back(thread(detectMoInFile, detPath, recPath, share)); } else { recLog("one or both fetch cmds failed.", share); } - recLog("fetch results:", share); - - for (auto &&ret : rets) - { - recLog("cmd: " + ret->cmd + " return_code: " + to_string(ret->ret), share); - } + cleanupRes(rets); } + waitForDetThreads(share); + if (!share->skipCmd) { recLog("no motion detected", share);