From 973bea20c4e69923c92d9d56d1b7ea692192cbc0 Mon Sep 17 00:00:00 2001 From: MistEO Date: Wed, 21 Sep 2022 23:26:49 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=B0=9D=E8=AF=95=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E8=B0=83=E7=94=A8=E5=91=BD=E4=BB=A4=E6=97=B6=E6=8A=9B=E5=87=BA?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix https://github.com/MaaAssistantArknights/MaaAssistantArknights/issues/1871 --- src/MeoAssistant/AsstPlatformWin32.cpp | 10 +++++++--- src/MeoAssistant/Controller.cpp | 6 ++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/MeoAssistant/AsstPlatformWin32.cpp b/src/MeoAssistant/AsstPlatformWin32.cpp index 3956accc5b..aea21cef68 100644 --- a/src/MeoAssistant/AsstPlatformWin32.cpp +++ b/src/MeoAssistant/AsstPlatformWin32.cpp @@ -164,7 +164,7 @@ std::string asst::utils::callcmd(const std::string& cmdline) OVERLAPPED pipeov { .hEvent = CreateEventW(nullptr, TRUE, FALSE, nullptr) }; (void)ReadFile(pipe_parent_read, pipe_buffer.get(), PipeBuffSize, nullptr, &pipeov); - while (1) { + while (true) { wait_handles.clear(); if (process_running) wait_handles.push_back(process_info.hProcess); if (!pipe_eof) wait_handles.push_back(pipeov.hEvent); @@ -181,7 +181,9 @@ std::string asst::utils::callcmd(const std::string& cmdline) else { // something bad happened err = GetLastError(); - throw std::system_error(std::error_code(err, std::system_category())); + // throw std::system_error(std::error_code(err, std::system_category())); + Log.error(__FUNCTION__, "A fatal error occurred", err); + break; } if (signaled_object == process_info.hProcess) { @@ -208,7 +210,9 @@ std::string asst::utils::callcmd(const std::string& cmdline) CloseHandle(process_info.hProcess); CloseHandle(process_info.hThread); CloseHandle(pipe_parent_read); - CloseHandle(pipeov.hEvent); + if (pipeov.hEvent) { + CloseHandle(pipeov.hEvent); + } return pipe_str; } diff --git a/src/MeoAssistant/Controller.cpp b/src/MeoAssistant/Controller.cpp index 6b09575a3b..5bf481f7ad 100644 --- a/src/MeoAssistant/Controller.cpp +++ b/src/MeoAssistant/Controller.cpp @@ -51,7 +51,7 @@ asst::Controller::Controller(AsstCallback callback, void* callback_arg) fcntl(m_pipe_out[PIPE_READ], F_SETFL, O_NONBLOCK); if (pipe_in_ret < 0 || pipe_out_ret < 0) { - throw "controller pipe created failed"; + Log.error(__FUNCTION__, "controller pipe created failed", pipe_in_ret, pipe_out_ret); } m_support_socket = false; #endif @@ -293,7 +293,9 @@ std::optional asst::Controller::call_command(const std::string& cmd else { // something bad happened err = GetLastError(); - throw std::system_error(std::error_code(err, std::system_category())); + // throw std::system_error(std::error_code(err, std::system_category())); + Log.error(__FUNCTION__, "A fatal error occurred", err); + break; } if (signaled_object == process_info.hProcess) {