From 51bf928d02b8cbf8d7f343daead32c8df1550cdc Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 14 Dec 2010 18:43:25 +0000 Subject: [PATCH] Fail instead of crashing in wxGTK wxCursor::CloneGDIRefData(). CloneGDIRefData() used wxCursorRefData copy ctor which wasn't implemented correctly and simply copied its internal m_cursor member without incrementing its reference count which resulted in a crash when it was then dereferenced twice. Unfortunately there doesn't seem to be any simple way to clone GDK cursors but as this should be something only rarely (if ever?) needed, simply don't implement CloneGDIRefData() at all for now and just leave an assert in it if it's ever really called. Also don't define wxCursorRefData copy ctor at all as it can't be done correctly. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66371 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/gtk/cursor.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/gtk/cursor.cpp b/src/gtk/cursor.cpp index 76d5822955..3ebc5e1a4f 100644 --- a/src/gtk/cursor.cpp +++ b/src/gtk/cursor.cpp @@ -36,6 +36,11 @@ public: virtual bool IsOk() const { return m_cursor != NULL; } GdkCursor *m_cursor; + +private: + // There is no way to copy m_cursor so we can't implement a copy ctor + // properly. + wxDECLARE_NO_COPY_CLASS(wxCursorRefData); }; wxCursorRefData::wxCursorRefData() @@ -348,9 +353,17 @@ wxGDIRefData *wxCursor::CreateGDIRefData() const return new wxCursorRefData; } -wxGDIRefData *wxCursor::CloneGDIRefData(const wxGDIRefData *data) const +wxGDIRefData * +wxCursor::CloneGDIRefData(const wxGDIRefData * WXUNUSED(data)) const { - return new wxCursorRefData(*static_cast(data)); + // TODO: We can't clone GDK cursors at the moment. To do this we'd need + // to remember the original data from which the cursor was created + // (i.e. standard cursor type or the bitmap) or use + // gdk_cursor_get_cursor_type() (which is in 2.22+ only) and + // gdk_cursor_get_image(). + wxFAIL_MSG( wxS("Cloning cursors is not implemented in wxGTK.") ); + + return new wxCursorRefData; } //----------------------------------------------------------------------------- -- 2.45.2