# GenericDirCtrl Bus Error crash on OSX

**URL:** <https://www.ruby-forum.com/t/genericdirctrl-bus-error-crash-on-osx/153002>\
**Category:** wxRuby\
**Created:** [November 11, 2008, 1:01am UTC](https://www.ruby-forum.com/t/genericdirctrl-bus-error-crash-on-osx/153002 "2008-11-11T01:01:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mathias\_Bruce](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/82dd89/32.png) [@Mathias\_Bruce](https://www.ruby-forum.com/u/Mathias_Bruce)\
**Post date:** [November 11, 2008, 1:01am UTC](https://www.ruby-forum.com/t/genericdirctrl-bus-error-crash-on-osx/153002/1 "2008-11-11T01:01:35Z")

</div>

Hi all and thanks to everyone working on this project =o)  
I have a problem, and I suspect it has its origins in WxRuby…  
In my program I use a GenericDirCtrl and handle its corresponding  
TreeCtrl item selection event with evt\_tree\_sel\_changed.  
In the method handling this event, I try to get at the data of the  
selected item, but I run into this:

./my\_xrcise\_frames.rb:43: [BUG] Bus Error  
ruby 1.8.6 (2008-03-03) [universal-darwin9.0]

Abort trap

The code for the event handling method is as follows, where  
gdc\_browse\_tree is the GenericDirCtrl instance:

def on\_browse\_tree\_sel\_changed(tree\_event)  
item\_id = tree\_event.get\_item  
raise ‘item\_id was zero’ if item\_id == 0  
tc = gdc\_browse\_tree.get\_tree\_ctrl  
item\_data = tc.get\_item\_data(item\_id)  
raise ‘item\_data was nil’ if item\_data == nil  
end

The line number referenced in the crash bus error (43) is the  
“item\_data == nil” comparison. The exception doesn’t get raised - the  
application just crashes. I tried to reproduce it by catching the same  
event by modifying the treectrl.rb sample, so I could send you code  
you were already very familiar with, but the error didn’t appear then.  
It seems to require a GenericDirCtrl.

I’m running:  
OSX 10.5  
ruby 1.8.6 (2008-03-03 patchlevel 114) [universal-darwin9.0]  
wx\_sugar (0.1.20)  
wxruby (1.9.9)

Any help is greatly appreciated! If I have omitted any important  
information from this mail, tell me and I will do my best to provide  
it. I have used wxruby with great results on linux, and I hope to be  
doing the same on OSX in the future.

Best regards,  
Mathias

---

<div class="post-metadata">

**Author:** ![Mathias\_Bruce](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/82dd89/32.png) [@Mathias\_Bruce](https://www.ruby-forum.com/u/Mathias_Bruce)\
**Post date:** [November 11, 2008, 1:38am UTC](https://www.ruby-forum.com/t/genericdirctrl-bus-error-crash-on-osx/153002/2 "2008-11-11T01:38:27Z")

</div>

Mathias Bruce wrote:

> The code for the event handling method is as follows, where  
> gdc\_browse\_tree is the GenericDirCtrl instance:
> 
> def on\_browse\_tree\_sel\_changed(tree\_event)  
> item\_id = tree\_event.get\_item  
> raise ‘item\_id was zero’ if item\_id == 0  
> tc = gdc\_browse\_tree.get\_tree\_ctrl  
> item\_data = tc.get\_item\_data(item\_id)  
> raise ‘item\_data was nil’ if item\_data == nil  
> end

Thanks for reporting this. I think it’s a bug. In a normal Wx::TreeCtrl  
get\_item\_data works fine, but the item data held by a TreeCtrl  
associated with a GenericDirCtrl isn’t a valid ruby object. We can fix  
this, and it would be helpful to understand what you were trying to do  
here.

Could you say what you expected to get from calling get\_item\_data here  
please? The GenericDirCtrl already has methods (eg get\_path,  
get\_file\_path) that will return the value of the currently selected  
directory.

BTW, it’s very much appreciated if you can demonstrate a problem in a  
minimal, self-contained, runnable sample, rather than just a isolated  
snippet. That saves those looking into it having to guess how to  
reproduce the context of the problem.

thanks  
alex

---

<div class="post-metadata">

**Author:** ![Mathias\_Bruce](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/82dd89/32.png) [@Mathias\_Bruce](https://www.ruby-forum.com/u/Mathias_Bruce)\
**Post date:** [November 11, 2008, 2:07am UTC](https://www.ruby-forum.com/t/genericdirctrl-bus-error-crash-on-osx/153002/3 "2008-11-11T02:07:43Z")

</div>

On Tue, Nov 11, 2008 at 1:36 AM, Alex F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > Abort trap  
> > end
> 
> [http://rubyforge.org/mailman/listinfo/wxruby-users](http://rubyforge.org/mailman/listinfo/wxruby-users)

Thanks for the quick reply! I apparently misread the docs gravely, and  
got the impression that I had to pick the selected path from the item  
itself. GenericDirCtrl.get\_path does exactly what I needed… Sorry  
for wasting your time =o)

I read on the website about you preferring self-contained error  
reproduction code, and I completely understand that. The only reason I  
didn’t do that was because I’m using XRC and xrcise, so (I think) it  
would have been 2-3 separate files, in which case it would be easier  
to file a bug in the tracker and put them there. I just thought I’d  
find out if the problem was wxruby-related or not, first.

If you still want a little package of code reproducing the error, then  
I’ll absolutely cook it up, but you don’t need to extend the bindings  
for my sake anymore, since as you correctly suspected I didn’t really  
need the item data - and maybe no one else will either… =o)

Thanks again,  
Mathias

---

<div class="post-metadata">

**Author:** ![Mathias\_Bruce](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/82dd89/32.png) [@Mathias\_Bruce](https://www.ruby-forum.com/u/Mathias_Bruce)\
**Post date:** [November 11, 2008, 3:44am UTC](https://www.ruby-forum.com/t/genericdirctrl-bus-error-crash-on-osx/153002/4 "2008-11-11T03:44:51Z")

</div>

Mathias Bruce wrote:

> for wasting your time =o)

NP, you haven’t wasted my time at all. It helps the dev team understand  
where the docs could be clearer. As I said, thanks for reporting the  
issue; we can look into making wxRuby give more helpful error messages  
than crashing with a “bus error”.

> I read on the website about you preferring self-contained error  
> reproduction code, and I completely understand that. The only reason I  
> didn’t do that was because I’m using XRC and xrcise, so (I think) it  
> would have been 2-3 separate files, in which case it would be easier  
> to file a bug in the tracker and put them there. I just thought I’d  
> find out if the problem was wxruby-related or not, first.

Simply from experience, taking a problem down to a minimal example is  
often a good way to figure out where the error is coming from.

cheers  
alex
