From 53e85591c3a21ba9d94f8ed02a788d8b1ee2d64a Mon Sep 17 00:00:00 2001 From: Toshi Nagata Date: Sat, 25 Dec 2021 19:55:16 +0900 Subject: [PATCH] Calling subprocess sometimes causes a crash. Hopefully fixed (particularly on Windows) --- MolLib/Ruby_bind/ruby_bind.c | 7 +++++-- wxSources/MyApp.cpp | 9 ++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/MolLib/Ruby_bind/ruby_bind.c b/MolLib/Ruby_bind/ruby_bind.c index 86f95ab..6a9f2fc 100644 --- a/MolLib/Ruby_bind/ruby_bind.c +++ b/MolLib/Ruby_bind/ruby_bind.c @@ -928,6 +928,7 @@ static VALUE s_Kernel_CallSubProcess(int argc, VALUE *argv, VALUE self) { VALUE cmd, procname, cproc, stdout_val, stderr_val; + VALUE save_interruptFlag; int n, exitstatus, pid; char *sout, *serr; FILE *fpout, *fperr; @@ -972,9 +973,11 @@ s_Kernel_CallSubProcess(int argc, VALUE *argv, VALUE self) rb_raise(rb_eMolbyError, "Cannot open file for standard output (%s)", serr); } } - + + save_interruptFlag = s_SetInterruptFlag(self, Qnil); n = MyAppCallback_callSubProcess(StringValuePtr(cmd), StringValuePtr(procname), (cproc == Qnil ? NULL : s_Kernel_CallSubProcess_Callback), (cproc == Qnil ? NULL : (void *)cproc), fpout, fperr, &exitstatus, &pid); - + s_SetInterruptFlag(self, save_interruptFlag); + if (fpout != NULL && fpout != (FILE *)1) fclose(fpout); if (fperr != NULL && fperr != (FILE *)1) diff --git a/wxSources/MyApp.cpp b/wxSources/MyApp.cpp index 2f7575e..9a4e43d 100755 --- a/wxSources/MyApp.cpp +++ b/wxSources/MyApp.cpp @@ -730,7 +730,7 @@ MyApp::ShowProgressPanel(const char *mes) { wxString string((mes ? mes : ""), WX_DEFAULT_CONV); if (m_progressDialog == NULL) { - m_progressDialog = new wxProgressDialog(wxT("Progress"), mes); + m_progressDialog = new wxProgressDialog(wxT("Progress"), mes, 100, NULL, wxPD_APP_MODAL | wxPD_CAN_ABORT); } /* #if __WXMAC__ @@ -752,6 +752,7 @@ void MyApp::HideProgressPanel() { if (m_progressDialog != NULL) { + m_progressDialog->Hide(); m_progressDialog->Destroy(); m_progressDialog = NULL; } @@ -1516,7 +1517,7 @@ MyApp::CallSubProcess(const char *cmdline, const char *procname, int (*callback) nn = 0; } #endif - if (m_process->IsTerminated()) { + if (m_process->IsTerminated() || !wxProcess::Exists(pid)) { /* The subprocess has terminated */ status = m_process->GetStatus(); break; @@ -1544,6 +1545,7 @@ MyApp::CallSubProcess(const char *cmdline, const char *procname, int (*callback) status = -2; /* User interrupt */ } m_process->Detach(); + m_process = NULL; break; } } @@ -1556,7 +1558,7 @@ MyApp::CallSubProcess(const char *cmdline, const char *procname, int (*callback) } if (m_process != NULL) { - delete m_process; + m_process->Detach(); m_process = NULL; } @@ -1894,6 +1896,7 @@ wxBetterProcess::GetLineSub(wxString &outStr, wxInputStream *stream, wxMemoryBuf } if (trial > 0) { // stream->Read() is called only once + outStr = _T(""); if (err == wxSTREAM_EOF) return -1; // EOF and no data left return 0; // Not EOF, but no data is available at present -- 2.11.0