Bug with DataObjectComposite

Hi,

I think I’ve found a bug in wx.DataObjectComposite. The following snippet sets a circle, in metafile format, to the clipboard. It works fine if the metafile is set directly to the clipboard (1), but it crashes if, instead, the metafile is added to a DataObjectComposite, which, in turn, is set to the clipboard (2):

if wx.TheClipboard.Open():

Draw on Metafile

dc = wx.MetaFileDC("", 10, 10)
dc.DrawCircle(5, 5, 5)
m = dc.Close() # Get a wx.MetaFile from the wx.MetaFileDC
mdo = wx.MetafileDataObject()
mdo.SetMetafile(m)

(1) Set Metafile on clipboard directly

wx.TheClipboard.AddData(mdo) # --> ok :slight_smile:

(2) Add Metafile to a DataObjectComposite instead

#do = wx.DataObjectComposite()
#do.Add(mdo)
#wx.TheClipboard.AddData(do) # --> crash :frowning:

Option (2) causes Python to crash when you paste on another application. I’m using wxPython 2.9.2.2, Python 2.7, Windows Vista 32 bit.

It could be worthy to note that simply adding the metafile to the DataObjectComposite causes the crash, even if Clipboard is set with the metafile – not the DataObjectComposite object, i.e.

(3) Add Metafile to a DataObjectComposite but set Metafile to Clipboard

#wx.TheClipboard.AddData(mdo)
#do = wx.DataObjectComposite()
#do.Add(mdo) # --> crash :frowning:

Could it be a bug related to reference counting / object ownership?

Thanks and best regards,
Luca