From 3450f21ccf1c6a2c1117c93d89f9537605521035 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 5 Jul 2000 19:27:30 +0000 Subject: [PATCH] fixed wxColourDialog crash git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@7698 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/dialog.h | 3 +++ include/wx/gtk1/dialog.h | 3 +++ src/common/wincmn.cpp | 5 +++++ src/common/zstream.cpp | 9 ++++++++- src/generic/colrdlgg.cpp | 3 --- src/gtk/dialog.cpp | 20 ++++++++++++-------- src/gtk1/dialog.cpp | 20 ++++++++++++-------- 7 files changed, 43 insertions(+), 20 deletions(-) diff --git a/include/wx/gtk/dialog.h b/include/wx/gtk/dialog.h index c996833727..7050e0b05e 100644 --- a/include/wx/gtk/dialog.h +++ b/include/wx/gtk/dialog.h @@ -103,6 +103,9 @@ protected: // common part of all ctors void Init(); + // common part of Destroy() and ~wxDialog + void CleanUp(); + virtual void DoSetSize(int x, int y, int width, int height, int sizeFlags = wxSIZE_AUTO); diff --git a/include/wx/gtk1/dialog.h b/include/wx/gtk1/dialog.h index c996833727..7050e0b05e 100644 --- a/include/wx/gtk1/dialog.h +++ b/include/wx/gtk1/dialog.h @@ -103,6 +103,9 @@ protected: // common part of all ctors void Init(); + // common part of Destroy() and ~wxDialog + void CleanUp(); + virtual void DoSetSize(int x, int y, int width, int height, int sizeFlags = wxSIZE_AUTO); diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index 2f43d0d55a..e40b8f23c4 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -504,6 +504,11 @@ void wxWindowBase::AddChild(wxWindowBase *child) { wxCHECK_RET( child, wxT("can't add a NULL child") ); + // this should never happen and it will lead to a crash later if it does + // because RemoveChild() will remove only one node from the children list + // and the other(s) one(s) will be left with dangling pointers in them + wxASSERT_MSG( !GetChildren().Find(child), _T("AddChild() called twice") ); + GetChildren().Append(child); child->SetParent(this); } diff --git a/src/common/zstream.cpp b/src/common/zstream.cpp index c4593c293f..e0285c9db1 100644 --- a/src/common/zstream.cpp +++ b/src/common/zstream.cpp @@ -85,7 +85,7 @@ size_t wxZlibInputStream::OnSysRead(void *buffer, size_t size) while (m_inflate->avail_out > 0) { if (m_inflate->avail_in == 0) { - m_parent_i_stream->Read(m_z_buffer, m_z_size); + m_parent_i_stream->Read(m_z_buffer, wxMin(m_z_size, size)); m_inflate->next_in = m_z_buffer; m_inflate->avail_in = m_parent_i_stream->LastRead(); @@ -95,6 +95,13 @@ size_t wxZlibInputStream::OnSysRead(void *buffer, size_t size) m_lasterror = m_parent_i_stream->LastError(); return 0; // failed to read anything } + + if ( m_inflate->avail_in == 0 ) + { + // EOF + m_lasterror = wxStream_EOF; + break; + } } err = inflate(m_inflate, Z_FINISH); if (err == Z_STREAM_END) diff --git a/src/generic/colrdlgg.cpp b/src/generic/colrdlgg.cpp index ebea49547b..4cc5493335 100644 --- a/src/generic/colrdlgg.cpp +++ b/src/generic/colrdlgg.cpp @@ -123,9 +123,6 @@ wxGenericColourDialog::wxGenericColourDialog() wxGenericColourDialog::wxGenericColourDialog(wxWindow *parent, wxColourData *data) - : wxDialog(parent, -1, wxT("Colour"), - wxPoint(0, 0), wxSize(900, 900), - wxDEFAULT_DIALOG_STYLE | wxDIALOG_MODAL) { whichKind = 1; colourSelection = 0; diff --git a/src/gtk/dialog.cpp b/src/gtk/dialog.cpp index 5cd3594dfb..25f2982814 100644 --- a/src/gtk/dialog.cpp +++ b/src/gtk/dialog.cpp @@ -314,9 +314,7 @@ bool wxDialog::Create( wxWindow *parent, wxDialog::~wxDialog() { - Destroy(); - - m_isBeingDeleted = TRUE; + CleanUp(); if ((wxTopLevelWindows.Number() == 0) && (wxTheApp->GetExitOnFrameDelete())) @@ -328,13 +326,12 @@ wxDialog::~wxDialog() void wxDialog::SetTitle( const wxString& title ) { m_title = title; - if (m_title.IsNull()) m_title = wxT(""); gtk_window_set_title( GTK_WINDOW(m_widget), m_title.mbc_str() ); } wxString wxDialog::GetTitle() const { - return (wxString&)m_title; + return m_title; } void wxDialog::OnApply( wxCommandEvent &WXUNUSED(event) ) @@ -366,7 +363,7 @@ void wxDialog::OnOK( wxCommandEvent &WXUNUSED(event) ) else { SetReturnCode(wxID_OK); - this->Show(FALSE); + Show(FALSE); } } } @@ -415,14 +412,21 @@ bool wxDialog::Destroy() // don't leave a dangling pointer as the app top window, we can be deleted // any moment at all now! + CleanUp(); + + return TRUE; +} + +void wxDialog::CleanUp() +{ + m_isBeingDeleted = TRUE; + if ( wxTheApp->GetTopWindow() == this ) { wxTheApp->SetTopWindow( (wxWindow*) NULL ); } wxTopLevelWindows.DeleteObject( this ); - - return TRUE; } void wxDialog::OnSize( wxSizeEvent &WXUNUSED(event) ) diff --git a/src/gtk1/dialog.cpp b/src/gtk1/dialog.cpp index 5cd3594dfb..25f2982814 100644 --- a/src/gtk1/dialog.cpp +++ b/src/gtk1/dialog.cpp @@ -314,9 +314,7 @@ bool wxDialog::Create( wxWindow *parent, wxDialog::~wxDialog() { - Destroy(); - - m_isBeingDeleted = TRUE; + CleanUp(); if ((wxTopLevelWindows.Number() == 0) && (wxTheApp->GetExitOnFrameDelete())) @@ -328,13 +326,12 @@ wxDialog::~wxDialog() void wxDialog::SetTitle( const wxString& title ) { m_title = title; - if (m_title.IsNull()) m_title = wxT(""); gtk_window_set_title( GTK_WINDOW(m_widget), m_title.mbc_str() ); } wxString wxDialog::GetTitle() const { - return (wxString&)m_title; + return m_title; } void wxDialog::OnApply( wxCommandEvent &WXUNUSED(event) ) @@ -366,7 +363,7 @@ void wxDialog::OnOK( wxCommandEvent &WXUNUSED(event) ) else { SetReturnCode(wxID_OK); - this->Show(FALSE); + Show(FALSE); } } } @@ -415,14 +412,21 @@ bool wxDialog::Destroy() // don't leave a dangling pointer as the app top window, we can be deleted // any moment at all now! + CleanUp(); + + return TRUE; +} + +void wxDialog::CleanUp() +{ + m_isBeingDeleted = TRUE; + if ( wxTheApp->GetTopWindow() == this ) { wxTheApp->SetTopWindow( (wxWindow*) NULL ); } wxTopLevelWindows.DeleteObject( this ); - - return TRUE; } void wxDialog::OnSize( wxSizeEvent &WXUNUSED(event) )