# Copy/Paste problems in dragdrop.rb

**URL:** <https://www.ruby-forum.com/t/copy-paste-problems-in-dragdrop-rb/158322>\
**Category:** wxRuby\
**Created:** [January 22, 2009, 2:06am UTC](https://www.ruby-forum.com/t/copy-paste-problems-in-dragdrop-rb/158322 "2009-01-22T02:06:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rmcghee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b5ac83/32.png) [@rmcghee](https://www.ruby-forum.com/u/rmcghee)\
**Post date:** [January 22, 2009, 2:06am UTC](https://www.ruby-forum.com/t/copy-paste-problems-in-dragdrop-rb/158322/1 "2009-01-22T02:06:01Z")

</div>

Windows XP Professional + SP3  
ruby 1.8.6  
wxRuby 1.9.9

The drag and drop sample results in segmentation faults.

Instructions to reproduce:

1. Run dragdrop.rb (…/samples/dragdrop/dragdrop.rb)

2. Click on Clipboard tab

3. Click on Copy image button  
(Immediate segmentation fault on my system)

4. Run dragdrop.rb

5. Click on Clipboard tab

6. Type some text in TextCtrl

7. Click the Copy text button

8. Click the Paste button 3 times  
(Segmentation fault 7 times in 10)

9. Repeat 4. and 5.  
(Segmentation fault 10 times in 10 within a few iterations)

10. Run dragdrop.rb

11. Click on Clipboard tab

12. Type some text in TextCtrl

13. Click the Copy text button

14. Resize the window

15. Click the Paste button  
(Immediate segmentation fault)

I believe I installed wxSugar but am not using it  
(no require ‘wxSugar’ in dragdrop.rb)  
Interestingly, …/wx/accessors.rb seems to reference  
wxSugar.

Anyone else able to reproduce?

Ridge

---

<div class="post-metadata">

**Author:** ![rmcghee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b5ac83/32.png) [@rmcghee](https://www.ruby-forum.com/u/rmcghee)\
**Post date:** [January 23, 2009, 1:03pm UTC](https://www.ruby-forum.com/t/copy-paste-problems-in-dragdrop-rb/158322/2 "2009-01-23T13:03:31Z")

</div>

Hi Ridge

Ridge M. wrote:

> Windows XP Professional + SP3  
> ruby 1.8.6  
> wxRuby 1.9.9
> 
> The drag and drop sample results in segmentation faults.

Thanks for the report. I hadn’t realised there was this problem in  
1.9.9.

The development version of wxRuby contains a major rework of the classes  
used in DnD and Clipboard, which have been very tricky to port because  
of the way they’re designed in wxWidgets.

We’ve still got one problem with Clipboard on Windows, but this is a  
blocking issue (actually, now the only one) for wxRuby 2.0, so it will  
be fixed for the next release.

cheers  
alex

---

<div class="post-metadata">

**Author:** ![rmcghee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b5ac83/32.png) [@rmcghee](https://www.ruby-forum.com/u/rmcghee)\
**Post date:** [February 7, 2009, 4:56am UTC](https://www.ruby-forum.com/t/copy-paste-problems-in-dragdrop-rb/158322/3 "2009-02-07T04:56:04Z")

</div>

Alex F. wrote:

> Hi Ridge
> 
> Ridge M. wrote:
> 
> > Windows XP Professional + SP3  
> > ruby 1.8.6  
> > wxRuby 1.9.9
> > 
> > The drag and drop sample results in segmentation faults.
> 
> Thanks for the report. I hadn’t realised there was this problem in  
> 1.9.9.
> 
> The development version of wxRuby contains a major rework of the classes  
> used in DnD and Clipboard, which have been very tricky to port because  
> of the way they’re designed in wxWidgets.
> 
> We’ve still got one problem with Clipboard on Windows, but this is a  
> blocking issue (actually, now the only one) for wxRuby 2.0, so it will  
> be fixed for the next release.
> 
> cheers  
> alex

Hi Alex,

Just a note –  
I repeated the above tests on 1.9.10.  
The good news is that Problem #1 has disappeared.  
The bad news is that Problems #2 and #3 still seg fault.  
I didn’t know whether “next release” meant 1.9.10 or 2.0.

Ridge

---

<div class="post-metadata">

**Author:** ![rmcghee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b5ac83/32.png) [@rmcghee](https://www.ruby-forum.com/u/rmcghee)\
**Post date:** [February 7, 2009, 7:35am UTC](https://www.ruby-forum.com/t/copy-paste-problems-in-dragdrop-rb/158322/4 "2009-02-07T07:35:31Z")

</div>

1.9.10 is wxRuby 2.0 RC1, but RubyGems doesn’t like us using this kind  
of  
naming scheme, so we have to use 1.9.10 to satisfy RubyGems.

---

<div class="post-metadata">

**Author:** ![rmcghee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b5ac83/32.png) [@rmcghee](https://www.ruby-forum.com/u/rmcghee)\
**Post date:** [February 7, 2009, 10:42am UTC](https://www.ruby-forum.com/t/copy-paste-problems-in-dragdrop-rb/158322/5 "2009-02-07T10:42:06Z")

</div>

Hi Ridge,

2009/2/7 Ridge M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> I repeated the above tests on 1.9.10.  
> The good news is that Problem #1 has disappeared.  
> The bad news is that Problems #2 and #3 still seg fault.

> 1. Run dragdrop.rb
> 2. Click on Clipboard tab
> 3. Type some text in TextCtrl
> 4. Click the Copy text button
> 5. Click the Paste button 3 times  
> (Segmentation fault 7 times in 10)
> 6. Repeat 4. and 5.  
> (Segmentation fault 10 times in 10 within a few iterations)

I’ve been able to reproduce this issue with wxRuby-1.9.10, ruby-1.9.1  
both on MinGW and Linux.  
There is no need to repeat 4 but I have to click on the Paste button  
many times.  
On Linux, sometimes the text becomes corrupted, other times the app seg  
faults.

> 1. Run dragdrop.rb
> 2. Click on Clipboard tab
> 3. Type some text in TextCtrl
> 4. Click the Copy text button
> 5. Resize the window
> 6. Click the Paste button  
> (Immediate segmentation fault)

I’ve been able to reproduce this issue with wxRuby-1.9.10, ruby-1.9.1  
both on MinGW and Linux.  
Sometimes, the crash occurs after the first click on Paste button,  
other times it occurs after several clicks on this button.  
Also on Linux, sometimes the text becomes corrupted, other times the  
app seg faults.

Chauk-Mean.

---

<div class="post-metadata">

**Author:** ![rmcghee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b5ac83/32.png) [@rmcghee](https://www.ruby-forum.com/u/rmcghee)\
**Post date:** [February 7, 2009, 7:14pm UTC](https://www.ruby-forum.com/t/copy-paste-problems-in-dragdrop-rb/158322/6 "2009-02-07T19:14:05Z")

</div>

Ridge M. wrote:

> Just a note –  
> I repeated the above tests on 1.9.10.  
> The good news is that Problem #1 has disappeared.

Thanks for the update on these problems.

> The bad news is that Problems #2 and #3 still seg fault.

I can reproduce this on Linux. Fortunately I can see what the bug is,  
and it’s not hard to fix.

If this is causing a problem in your own program, you can work round it  
for now by retaining a reference to the data object being set in an  
instance variable. For example, in the clipboard sample, tweak the  
on\_copy\_text method to something like

@data\_obj = Wx::TextDataObject.new(@text.value)  
clipboard.data = @data\_obj

For reference, what’s happening is that the ruby data object is getting  
swept up by garbage collection, because it was only referenced by a  
local variable which is out of scope. When the time comes to retrieve  
the data to paste it, wxRuby tries to call ‘get\_text’ on that object -  
but it’s now disappeared so there’s a crash.

> I didn’t know whether “next release” meant 1.9.10 or 2.0.

The only real issues outstanding for 2.0 are these ones relating to  
clipboard. We decided to release 1.9.10 / RC1 as there were many other  
fixes and improvements which were worth getting into circulation.

cheers  
alex
