diff --git a/include/wx/unix/taskbarx11.h b/include/wx/unix/taskbarx11.h index d37c6c712e..f7d8589a13 100644 --- a/include/wx/unix/taskbarx11.h +++ b/include/wx/unix/taskbarx11.h @@ -36,6 +36,9 @@ public: protected: wxTaskBarIconArea *m_iconWnd; +private: + void OnDestroy(wxWindowDestroyEvent&); + DECLARE_DYNAMIC_CLASS(wxTaskBarIcon) }; diff --git a/src/unix/taskbarx11.cpp b/src/unix/taskbarx11.cpp index 06118f3109..55e11e8bdf 100644 --- a/src/unix/taskbarx11.cpp +++ b/src/unix/taskbarx11.cpp @@ -276,6 +276,14 @@ bool wxTaskBarIcon::IsIconInstalled() const return m_iconWnd != NULL; } +// Destroy event from wxTaskBarIconArea +void wxTaskBarIcon::OnDestroy(wxWindowDestroyEvent&) +{ + // prevent crash if wxTaskBarIconArea is destroyed by something else, + // for example if panel/kicker is killed + m_iconWnd = NULL; +} + bool wxTaskBarIcon::SetIcon(const wxIcon& icon, const wxString& tooltip) { wxBitmap bmp; @@ -286,6 +294,9 @@ bool wxTaskBarIcon::SetIcon(const wxIcon& icon, const wxString& tooltip) m_iconWnd = new wxTaskBarIconArea(this, bmp); if (m_iconWnd->IsOk()) { + m_iconWnd->Connect(wxEVT_DESTROY, + wxWindowDestroyEventHandler(wxTaskBarIcon::OnDestroy), + NULL, this); m_iconWnd->Show(); } else