]> git.saurik.com Git - wxWidgets.git/commitdiff
Fail instead of crashing in wxGTK wxCursor::CloneGDIRefData().
authorVadim Zeitlin <vadim@wxwidgets.org>
Tue, 14 Dec 2010 18:43:25 +0000 (18:43 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Tue, 14 Dec 2010 18:43:25 +0000 (18:43 +0000)
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

index 76d5822955390907b922eee00763f74853920e6b..3ebc5e1a4fce39cc0f9bbf1ccf06d24501d0b611 100644 (file)
@@ -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<const wxCursorRefData *>(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;
 }
 
 //-----------------------------------------------------------------------------