diff --git a/checkin_notes b/checkin_notes index 3a54561028..bb1b25fea9 100644 --- a/checkin_notes +++ b/checkin_notes @@ -7733,3 +7733,10 @@ David 18 Dec 2012 app.cpp makefile_sim sim.cpp + +Charlie 18 Dec 2012 + - Mgr: Fix potential crashes displaying notices asynchronously on Windows. + + clientgui/ + BOINCHtmlLBox.cpp,.h + BOINCInternetFSHandler.cpp diff --git a/clientgui/BOINCHtmlLBox.cpp b/clientgui/BOINCHtmlLBox.cpp index 3595e13523..b403e1bc3f 100644 --- a/clientgui/BOINCHtmlLBox.cpp +++ b/clientgui/BOINCHtmlLBox.cpp @@ -37,6 +37,9 @@ const wxChar BOINCHtmlListBoxNameStr[] = wxT("BOINCHtmlListBox"); IMPLEMENT_ABSTRACT_CLASS(CBOINCHtmlListBox, wxHtmlListBox) +BEGIN_EVENT_TABLE(CBOINCHtmlListBox, wxHtmlListBox) + EVT_MOTION(CBOINCHtmlListBox::OnMouseMove) +END_EVENT_TABLE() // ---------------------------------------------------------------------------- // CBOINCHtmlListBox creation @@ -84,18 +87,3 @@ CBOINCHtmlListBox::OnHTMLOpeningURL(wxHtmlURLType (type), return wxHTML_OPEN; } - -wxCoord CBOINCHtmlListBox::OnMeasureItem(size_t n) const { - CMainDocument* pDoc = wxGetApp().GetDocument(); - - wxASSERT(pDoc); - - size_t x = pDoc->notices.notices.size(); - if (n < x) { - NOTICE *ntc = pDoc->notices.notices[n]; - if (ntc == NULL) return 0; - return wxHtmlListBox::OnMeasureItem(n); - } - return 0; -} - diff --git a/clientgui/BOINCHtmlLBox.h b/clientgui/BOINCHtmlLBox.h old mode 100644 new mode 100755 index 0484a6a4ba..a3ea016579 --- a/clientgui/BOINCHtmlLBox.h +++ b/clientgui/BOINCHtmlLBox.h @@ -65,12 +65,17 @@ protected: wxColour GetSelectedTextColour(const wxColour& colFg) const { return colFg; } wxColour GetSelectedTextBgColour(const wxColour& colBg) const { return colBg; } void OnDrawBackground(wxDC&, const wxRect&, size_t) const {} - wxCoord OnMeasureItem(size_t n) const; + + // The following overrides of methods in wxHtmlListBox + // reduce CPU usage and avoid crashes + void OnMouseMove(wxMouseEvent&) {} + void OnInternalIdle() {} private: virtual wxHtmlOpeningStatus OnHTMLOpeningURL(wxHtmlURLType type, const wxString& url, wxString *redirect) const; + DECLARE_EVENT_TABLE() DECLARE_NO_COPY_CLASS(CBOINCHtmlListBox) }; diff --git a/clientgui/BOINCInternetFSHandler.cpp b/clientgui/BOINCInternetFSHandler.cpp old mode 100644 new mode 100755 index 20e683c401..b626279b30 --- a/clientgui/BOINCInternetFSHandler.cpp +++ b/clientgui/BOINCInternetFSHandler.cpp @@ -21,15 +21,20 @@ class MemFSHashObj : public wxObject public: MemFSHashObj(wxInputStream* stream, const wxString& mime) { - wxMemoryOutputStream out; - stream->Read(out); - m_Len = out.GetSize(); - m_Data = new char[m_Len]; - out.CopyTo(m_Data, m_Len); + if (stream) { + wxMemoryOutputStream out; + stream->Read(out); + m_Len = out.GetSize(); + m_Data = new char[m_Len]; + out.CopyTo(m_Data, m_Len); + } else { + m_Len = 0; + m_Data = NULL; + } m_MimeType = mime; m_Time = wxDateTime::Now(); } - + virtual ~MemFSHashObj() { delete[] m_Data; @@ -242,7 +247,6 @@ size_t wxWinINetInputStream::OnSysRead(void *buffer, size_t bufsize) if ((lError == WSAEWOULDBLOCK) || (lError == ERROR_IO_PENDING)){ while (!operationEnded) { if (b_ShuttingDown || (!pDoc->IsConnected())) { -// if (b_ShuttingDown) { SetError(wxSTREAM_EOF); return 0; } @@ -320,6 +324,12 @@ wxWinINetInputStream::~wxWinINetInputStream() wxInputStream *wxWinINetURL::GetInputStream(wxURL *owner) { +static bool bAlreadyRunning = false; + if (bAlreadyRunning) { + printf(stderr, "wxWinINetURL::GetInputStream reentered!"); + return NULL; + } + bAlreadyRunning = true; DWORD service; CMainDocument* pDoc = wxGetApp().GetDocument(); @@ -327,6 +337,7 @@ wxInputStream *wxWinINetURL::GetInputStream(wxURL *owner) if (b_ShuttingDown || (!pDoc->IsConnected())) { GetSessionHandle(); // Closes the session + bAlreadyRunning = false; return 0; } @@ -340,6 +351,7 @@ wxInputStream *wxWinINetURL::GetInputStream(wxURL *owner) } else { + bAlreadyRunning = false; // unknown protocol. Let wxURL try another method. return 0; } @@ -370,8 +382,10 @@ wxInputStream *wxWinINetURL::GetInputStream(wxURL *owner) delete newStream; newStream = NULL; } + bAlreadyRunning = false; return 0; } + wxGetApp().Yield(true); } @@ -380,13 +394,23 @@ wxInputStream *wxWinINetURL::GetInputStream(wxURL *owner) (!b_ShuttingDown) ) { INTERNET_ASYNC_RESULT* res = (INTERNET_ASYNC_RESULT*)lastlpvStatusInformation; - newStreamHandle = (HINTERNET)(res->dwResult); + if (res) { + newStreamHandle = (HINTERNET)(res->dwResult); + } else { + newStreamHandle = NULL; + } + } + + if (!newStreamHandle) { + bAlreadyRunning = false; + return NULL; } newStream->Attach(newStreamHandle); InternetSetStatusCallback(newStreamHandle, BOINCInternetStatusCallback); // IS THIS NEEDED??? +bAlreadyRunning = false; return newStream; } @@ -480,29 +504,25 @@ wxFSFile* CBOINCInternetFSHandler::OpenFile(wxFileSystem& WXUNUSED(fs), const wx strMIME = GetMimeTypeFromExt(strLocation); } - if (m_InputStream) - { - obj = new MemFSHashObj(m_InputStream, strMIME); - delete m_InputStream; - m_InputStream = NULL; - - // If we couldn't read image, then return NULL so - // image tag handler displays "broken image" bitmap - if (obj->m_Len == 0) { - delete obj; - return NULL; - } - - m_Hash->Put(strLocation, obj); - - return new wxFSFile ( - new wxMemoryInputStream(obj->m_Data, obj->m_Len), - strLocation, - strMIME, - GetAnchor(strLocation), - obj->m_Time - ); + obj = new MemFSHashObj(m_InputStream, strMIME); + delete m_InputStream; + m_InputStream = NULL; + + m_Hash->Put(strLocation, obj); + + // If we couldn't read image, then return NULL so + // image tag handler displays "broken image" bitmap + if (obj->m_Len == 0) { + return NULL; } + + return new wxFSFile ( + new wxMemoryInputStream(obj->m_Data, obj->m_Len), + strLocation, + strMIME, + GetAnchor(strLocation), + obj->m_Time + ); } } else @@ -512,6 +532,12 @@ wxFSFile* CBOINCInternetFSHandler::OpenFile(wxFileSystem& WXUNUSED(fs), const wx strMIME = GetMimeTypeFromExt(strLocation); } + // If we couldn't read image, then return NULL so + // image tag handler displays "broken image" bitmap + if (obj->m_Len == 0) { + return NULL; + } + return new wxFSFile ( new wxMemoryInputStream(obj->m_Data, obj->m_Len), strLocation,