# Ruby/cocoa delegate issue

**URL:** <https://www.ruby-forum.com/t/ruby-cocoa-delegate-issue/61682>\
**Category:** Ruby\
**Created:** [May 26, 2006, 2:21am UTC](https://www.ruby-forum.com/t/ruby-cocoa-delegate-issue/61682 "2006-05-26T02:21:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Josh\_Huber](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3be4f8/32.png) [@Josh\_Huber](https://www.ruby-forum.com/u/Josh_Huber)\
**Post date:** [May 26, 2006, 2:21am UTC](https://www.ruby-forum.com/t/ruby-cocoa-delegate-issue/61682/1 "2006-05-26T02:21:07Z")

</div>

And when I say “issue”, I really mean “crash”. 😉

There wasn’t any information about a ruby-cocoa mailing list on  
[rubycocoa.sf.net](http://rubycocoa.sf.net), so I’m posting this question here. If there’s  
a better place to ask for rb-cocoa help, let me know.

I’m going through the “Cocoa Programming for Mac OS X” book, but  
using Ruby to implement each project instead of, or sometimes in  
addition to, objective-c.

Things have been going fine, but I’ve run into an issue which I  
can’t resolve. For those of you who have the book, I’m on page  
104, attempting to delegate from NSSpeechSynthesizer.

My class, AppController, has implemented the  
speechSynthesizer\_didFinishSpeaking method like so:

```
def speechSynthesizer_didFinishSpeaking(sender, finish)
    puts "speech stopped, finish = #{finish.to_i}"
end

```

… and awakeFromNib sets up the delegation from the speech  
synthesizer like so:

```
def awakeFromNib
    puts "AppController#awakeFromNib"
    @speechSynth = NSSpeechSynthesizer.alloc.initWithVoice(nil)
    @speechSynth.setDelegate(self)

    puts "setting initial color for color well"
    @colorWell.setColor(@textField.textColor)
end

```

Now, if I click on the “Stop” button, causing my “stop” method to  
get called, the delegate callback method works fine. The finish  
boolean is 0, as expected in this case:

```
def stop(sender)
    @speechSynth.stopSpeaking
end

```

_however_, if I let the speech complete instead of stopping  
before the end, my application crashes. Because of the lack of  
debugger integration with ruby/cocoa, I don’t get much help when  
this happens, either.

Here’s the backtrace from the GDB console at the time of the  
crash:

(gdb) bt  
#0 0x90a460f0 in objc\_msgSend ()  
#1 0x000a1638 in ocid\_get\_rbobj ()  
#2 0x0006f814 in ocid\_to\_rbobj ()  
#3 0x0006efc8 in ocdata\_to\_rbobj ()  
#4 0x000718a8 in override\_mixin\_class\_method\_list ()  
#5 0x00071d0c in override\_mixin\_class\_method\_list ()  
#6 0x000720d0 in override\_mixin\_class\_method\_list ()  
#7 0x00070ba4 in ocstr\_to\_rbstr ()  
#8 0x9296a034 in -[NSObject(NSForwardInvocation) forward::] ()  
#9 0x90a4b0b0 in \_objc\_msgForward ()  
#10 0x93bb3f4c in -[NSSpeechSynthesizer \_handleSpeechDoneCallback] ()  
#11 0x92983a00 in \_\_NSFireMainThreadPerform ()  
#12 0x90814a78 in \_\_CFRunLoopPerformPerform ()  
#13 0x907e44cc in \_\_CFRunLoopDoSources0 ()  
#14 0x907e39fc in \_\_CFRunLoopRun ()  
#15 0x907e347c in CFRunLoopRunSpecific ()  
#16 0x9321d980 in RunCurrentEventLoopInMode ()  
#17 0x9321d014 in ReceiveNextEventCommon ()  
#18 0x9321ce80 in BlockUntilNextEventMatchingListInMode ()  
#19 0x9371fe84 in \_DPSNextEvent ()  
#20 0x9371fb48 in -[NSApplication  
nextEventMatchingMask:untilDate:inMode:dequeue:] ()  
#21 0x9371c08c in -[NSApplication run] ()  
#22 0x9380cbfc in NSApplicationMain ()  
#23 0x00076f50 in init\_NSAlert ()  
#24 0x966b50c8 in rb\_with\_disable\_interrupt ()  
#25 0x966b5a84 in rb\_with\_disable\_interrupt ()  
#26 0x966b02e0 in rb\_Array ()  
#27 0x966ac0b0 in ruby\_cleanup ()  
#28 0x966ac10c in ruby\_exec ()  
#29 0x966ac154 in ruby\_run ()  
#30 0x00072658 in RBApplicationMain ()  
#31 0x00002d00 in main (argc=1, argv=0xbffff8dc) at main.m:13

I’m running OS 10.4.6 (ppc) with the latest ruby/cocoa package  
(0.4.2?).

If anyone has _any_ idea what might be going on here, please let  
me know. BTW, the equivilant objective-c implementation works  
correctly for me, so hopefully that means I’m not doing something  
dumb and there is a bug here… 😉

Thanks in advance,  
Josh

---

<div class="post-metadata">

**Author:** ![Josh\_Huber](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3be4f8/32.png) [@Josh\_Huber](https://www.ruby-forum.com/u/Josh_Huber)\
**Post date:** [June 1, 2006, 9:45am UTC](https://www.ruby-forum.com/t/ruby-cocoa-delegate-issue/61682/2 "2006-06-01T09:45:20Z")

</div>

On May 25, 2006, at 17:18, Josh Huber wrote:

> And when I say “issue”, I really mean “crash”. 😉
> 
> There wasn’t any information about a ruby-cocoa mailing list on  
> [rubycocoa.sf.net](http://rubycocoa.sf.net), so I’m posting this question here. If there’s  
> a better place to ask for rb-cocoa help, let me know.

removed\_email\_address@domain.invalid

🙂
