From c8354cf85833e1d4be66421b0b8b87ee15160c6d Mon Sep 17 00:00:00 2001 From: yangjiaxuan <171295266@qq.com> Date: Thu, 9 Nov 2023 14:57:33 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=9B=BE=E5=83=8F=E5=A4=84?= =?UTF-8?q?=E7=90=86=E6=AF=94=E8=BE=83=E5=A4=9A=E6=97=B6=EF=BC=8C=E7=82=B9?= =?UTF-8?q?=E5=87=BB=E6=89=AB=E6=8F=8F=E5=8F=96=E6=B6=88=EF=BC=8C=E7=95=8C?= =?UTF-8?q?=E9=9D=A2=E4=B8=80=E7=9B=B4=E7=AD=89=E5=BE=85=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hgdriver/hgdev/hg_scanner.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/hgdriver/hgdev/hg_scanner.cpp b/hgdriver/hgdev/hg_scanner.cpp index ee1c902..98f5fbd 100644 --- a/hgdriver/hgdev/hg_scanner.cpp +++ b/hgdriver/hgdev/hg_scanner.cpp @@ -1063,6 +1063,8 @@ void hg_scanner::thread_handle_image_process(void) //VLDReportLeaks(); //while (run_ && !user_cancel_) int cnt = 0; + bool invoke_stop = false; + while (run_) { std::shared_ptr tiny_buffer; @@ -1094,7 +1096,8 @@ void hg_scanner::thread_handle_image_process(void) { VLOG_MINI_1(LOG_LEVEL_FATAL, "[thread_handle_image_process]:Get Image Process is NULL pid is %d.\n", pid_); stop_fatal_ = SCANNER_ERR_INSUFFICIENT_MEMORY; - stop(); + do_stop(); + invoke_stop = true; break; } } @@ -1110,7 +1113,8 @@ void hg_scanner::thread_handle_image_process(void) else stop_fatal_ = SCANNER_ERR_INSUFFICIENT_MEMORY; VLOG_MINI_1(LOG_LEVEL_FATAL, "[thread_handle_image_process]:is opencv Fatal and stop scanner: %s\n", e.what()); - stop(); + do_stop(); + invoke_stop = true; break; } @@ -1118,7 +1122,9 @@ void hg_scanner::thread_handle_image_process(void) { VLOG_MINI_1(LOG_LEVEL_FATAL, "[thread_handle_image_process]:stop scanner!!! Insufficient memory when proecss image with %d bytes.\n", tiny_buffer->size()); stop_fatal_ = SCANNER_ERR_INSUFFICIENT_MEMORY; - stop(); + do_stop(); + invoke_stop = true; + break; } } else @@ -1128,6 +1134,15 @@ void hg_scanner::thread_handle_image_process(void) } LOG_INFO(LOG_LEVEL_DEBUG_INFO, "[thread_handle_image_process 'EXIT !!!']\n"); //VLDGlobalDisable(); + + // wait usb thread waiting ... + if (invoke_stop) // break on exception, enusre me quit at last + { + int times = 0; + while (!wait_usb_.is_waiting() && times++ < 200) + std::this_thread::sleep_for(std::chrono::milliseconds(5)); + imgs_.Clear(); + } } void hg_scanner::working_begin(void*) { @@ -3572,7 +3587,7 @@ std::shared_ptr hg_scanner::aquire_memory(int size, bool from_usb) mem.reset(); LOG_INFO(LOG_LEVEL_FATAL, "Can't aquire enough memory, working must be stopped!\n"); notify_ui_working_status(hg_log::lang_load(ID_STATU_DESC_SCANNER_ERR_INSUFFICIENT_MEMORY), SANE_EVENT_ERROR, SCANNER_ERR_INSUFFICIENT_MEMORY); - stop(); + do_stop(); } return mem;