解决图像处理比较多时,点击扫描取消,界面一直等待的问题

This commit is contained in:
yangjiaxuan 2023-11-09 14:57:33 +08:00
parent 87874c6cc4
commit c8354cf858
1 changed files with 19 additions and 4 deletions

View File

@ -1063,6 +1063,8 @@ void hg_scanner::thread_handle_image_process(void)
//VLDReportLeaks(); //VLDReportLeaks();
//while (run_ && !user_cancel_) //while (run_ && !user_cancel_)
int cnt = 0; int cnt = 0;
bool invoke_stop = false;
while (run_) while (run_)
{ {
std::shared_ptr<tiny_buffer> tiny_buffer; std::shared_ptr<tiny_buffer> 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_); 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_fatal_ = SCANNER_ERR_INSUFFICIENT_MEMORY;
stop(); do_stop();
invoke_stop = true;
break; break;
} }
} }
@ -1110,7 +1113,8 @@ void hg_scanner::thread_handle_image_process(void)
else else
stop_fatal_ = SCANNER_ERR_INSUFFICIENT_MEMORY; 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()); 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; 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()); 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_fatal_ = SCANNER_ERR_INSUFFICIENT_MEMORY;
stop(); do_stop();
invoke_stop = true;
break;
} }
} }
else 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"); LOG_INFO(LOG_LEVEL_DEBUG_INFO, "[thread_handle_image_process 'EXIT !!!']\n");
//VLDGlobalDisable(); //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*) void hg_scanner::working_begin(void*)
{ {
@ -3572,7 +3587,7 @@ std::shared_ptr<tiny_buffer> hg_scanner::aquire_memory(int size, bool from_usb)
mem.reset(); mem.reset();
LOG_INFO(LOG_LEVEL_FATAL, "Can't aquire enough memory, working must be stopped!\n"); 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); 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; return mem;