# Different (tree) event behaviors across platforms

**URL:** <https://www.ruby-forum.com/t/different-tree-event-behaviors-across-platforms/131630>\
**Category:** wxRuby\
**Created:** [March 12, 2008, 1:06am UTC](https://www.ruby-forum.com/t/different-tree-event-behaviors-across-platforms/131630 "2008-03-12T01:06:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![chauk-mean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/d07c76/32.png) [@chauk-mean](https://www.ruby-forum.com/u/chauk-mean)\
**Post date:** [March 12, 2008, 1:06am UTC](https://www.ruby-forum.com/t/different-tree-event-behaviors-across-platforms/131630/1 "2008-03-12T01:06:47Z")

</div>

Hi all,

I’m currently writing a simple outliner application as a tutorial on  
wxRuby (both will be soon released 😉 )  
I tested this application on Windows and Linux and found that the tree  
event behavior :

- is sometime strange on each platform
- is also different on each platform

Even if I managed to take care of these differences in the  
application, I’m just wondering if :

- they revealed some wxRuby issues ? wxWindows issues ?
- or it is normal ? In this case, I’d really appreciate some  
links/documentation on these cross-platforms issues.

You will find attached the source codes and captures of the  
application on Windows and Linux (Fedora 8).

So the symptoms :  
1/ Run outliner\_wo\_check.rb  
Clicking on the ‘Add Root’ button, creates an item and allow the  
edition of its label.  
On Windows, this works as expected. You can click several times and  
everything is fine.  
On Linux, this does not work. Sometimes, the editing of the label is  
not ended by the selection (through code) of another item. See the  
outliner\_linux\_wo\_check.jpg capture.

To fix this Linux issue, I added some checks to know if a label is  
being edited and to ensure that the editing is ended before adding  
items.

2/ Run outliner.rb  
If I create a root article, there are 2 selection change events on  
Windows (strange) and only one on Linux (as expected).  
See outliner\_linux.jpg and outliner\_windows.jpg.

3/ Run again outliner.rb :

- create two root articles, create a child within the first root as  
shown in outliner\_windows.jpg
- close the application afterwards

On Windows, you will see traces indicating that there are selection  
change events occuring during the close of the application ! On Linux,  
you don’t have these events.

This time for 2/ and 3/ I had to write code to face these strange  
things on Windows.

Thanks in advance for any help/clarification.

Cheers.

Chauk-Mean.

---

<div class="post-metadata">

**Author:** ![chauk-mean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/d07c76/32.png) [@chauk-mean](https://www.ruby-forum.com/u/chauk-mean)\
**Post date:** [March 13, 2008, 8:13pm UTC](https://www.ruby-forum.com/t/different-tree-event-behaviors-across-platforms/131630/2 "2008-03-13T20:13:05Z")

</div>

Hi

Chauk-Mean P wrote:

> I’m currently writing a simple outliner application as a tutorial on  
> wxRuby (both will be soon released 😉 )  
> I tested this application on Windows and Linux and found that the tree  
> event behavior :
> 
> - is sometime strange on each platform
> - is also different on each platform

Thank you for the report and test cases. As you know wxWidgets wraps  
native controls and the native event loop, and there are some subtle  
differences sometimes. From experience I think there are more of these  
in TreeCtrl than anywhere else - it’s probably because it’s the most  
complex native-wrapped control.

> Even if I managed to take care of these differences in the  
> application, I’m just wondering if :
> 
> - they revealed some wxRuby issues ? wxWindows issues ?
> - or it is normal ? In this case, I’d really appreciate some  
> links/documentation on these cross-platforms issues.

In most cases they’re wxWidgets issues, though ultimately the only way  
to verify this is to write a C++ sample. As for official docs, we’re  
limited to what’s in the wxWidgets docs, plus any annotations we make.  
In the past I’ve turned up useful confirmations of subtler  
cross-platform differences by searching for info on wxPython or C++ (eg  
by searching for wxTreeCtrl). The wxWiki sometimes also has info.

But usually it’s just a question of coding round it, as you’ve done.  
Happy to apply patches that note these differences in our ruby docs.

> You will find attached the source codes and captures of the  
> application on Windows and Linux (Fedora 8).

I tried out your examples, and was able to reproduce the differences you  
describe.

> 3/ Run again outliner.rb :
> 
> - create two root articles, create a child within the first root as  
> shown in outliner\_windows.jpg
> - close the application afterwards
> 
> On Windows, you will see traces indicating that there are selection  
> change events occuring during the close of the application ! On Linux,  
> you don’t have these events.  
> This might possibly be something fixable in wxRuby, but I’m not sure.  
> There’s a few places I’ve been surprised by ObjectPreviouslyDeleted  
> errors where events are getting sent to destroyed objects. I wonder if  
> wxRuby should try to explicitly disconnect event handlers on window  
> deletion - but there’s nothing in the C++ docs that suggests this.

cheers  
alex

---

<div class="post-metadata">

**Author:** ![chauk-mean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/d07c76/32.png) [@chauk-mean](https://www.ruby-forum.com/u/chauk-mean)\
**Post date:** [March 14, 2008, 3:52pm UTC](https://www.ruby-forum.com/t/different-tree-event-behaviors-across-platforms/131630/3 "2008-03-14T15:52:39Z")

</div>

Hi,

2008/3/13, Alex F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Thank you for the report and test cases. As you know wxWidgets wraps  
> native controls and the native event loop, and there are some subtle  
> differences sometimes. From experience I think there are more of these  
> in TreeCtrl than anywhere else - it’s probably because it’s the most  
> complex native-wrapped control.

Unfortunately, it is also one of the most useful control :-).

> In most cases they’re wxWidgets issues, though ultimately the only way  
> to verify this is to write a C++ sample. As for official docs, we’re  
> limited to what’s in the wxWidgets docs, plus any annotations we make.  
> In the past I’ve turned up useful confirmations of subtler  
> cross-platform differences by searching for info on wxPython or C++ (eg  
> by searching for wxTreeCtrl). The wxWiki sometimes also has info.

Thanks for the links. But after a quick search, I haven’t found a  
place where cross-platforms subtleties are documented. I will try a  
deeper search.

> Happy to apply patches that note these differences in our ruby docs.

I’m glad to add another little contribution to wxRuby.  
What do you think about having a general section on cross-platforms  
issues, or having such a section in each Control (when it is relevant)  
?

> > On Windows, you will see traces indicating that there are selection  
> > change events occuring during the close of the application ! On Linux,  
> > you don’t have these events.  
> > This might possibly be something fixable in wxRuby, but I’m not sure.  
> > There’s a few places I’ve been surprised by ObjectPreviouslyDeleted  
> > errors where events are getting sent to destroyed objects. I wonder if  
> > wxRuby should try to explicitly disconnect event handlers on window  
> > deletion - but there’s nothing in the C++ docs that suggests this.

This is exactly the problem I had. In the code of selection change  
event, I take and put the content of the textctrl (in the right pane)  
based on the selected item. But during the close of the window, the  
textctrl has been already destroyed. So I received this  
ObjectPreviouslyDeleted error.

It would be really great if wxRuby can deal with this issue.  
Indeed, unlike the 2 other issues, this one makes the application crash.

Cheers.

Chauk-Mean.

---

<div class="post-metadata">

**Author:** ![chauk-mean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/d07c76/32.png) [@chauk-mean](https://www.ruby-forum.com/u/chauk-mean)\
**Post date:** [April 16, 2008, 10:26am UTC](https://www.ruby-forum.com/t/different-tree-event-behaviors-across-platforms/131630/4 "2008-04-16T10:26:44Z")

</div>

Hi Chauk-Mean

Chauk-Mean P wrote:

> based on the selected item. But during the close of the window, the  
> textctrl has been already destroyed. So I received this  
> ObjectPreviouslyDeleted error.
> 
> It would be really great if wxRuby can deal with this issue.  
> Indeed, unlike the 2 other issues, this one makes the application crash.

I’ve just committed a patch (SVN:1664) to fix these  
ObjectPreviouslyDeleted errors sending events to destroyed Wx::Windows.

It seems to fix the samples; if possible, please test SVN HEAD to see  
whether the problem is resolved for you.

thanks  
alex
