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;