ndarilek / tts-rs

115 stars 25 forks source link

AVFoundation backend crash when getting voices in macOS desktop application #33

Closed helgoboss closed 1 year ago

helgoboss commented 2 years ago

First, thanks for making this crate! Very useful. I tried to integrate it into a desktop application and it crashes with a SIGSEGV when calling Tts::voices with the AVFoundation backend (in the hello_world example it doesn't crash):

Crashed Thread:        0  reaper  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BREAKPOINT (SIGTRAP)
Exception Codes:       0x0000000000000001, 0x000000018eda5438
Exception Note:        EXC_CORPSE_NOTIFY

Termination Reason:    Namespace SIGNAL, Code 5 Trace/BPT trap: 5
Terminating Process:   exc handler [13354]

Thread 0 Crashed:: reaper Dispatch queue: com.apple.main-thread
0   CoreFoundation                         0x18eda5438 _CFRelease.cold.3 + 92
1   CoreFoundation                         0x18eda5430 _CFRelease.cold.3 + 84
2   CoreFoundation                         0x18ed2b21c _CFRelease + 1496
3   libobjc.A.dylib                        0x18ea112b4 AutoreleasePoolPage::releaseUntil(objc_object**) + 196
4   libobjc.A.dylib                        0x18ea0db34 objc_autoreleasePoolPop + 212
...

I think it's because the code for getting the voices and voice attributes doesn't follow the Objective-C memory management rules (explained here in the context of Rust: https://stackoverflow.com/a/43148508, I also didn't know about these rules).

I'm going to create a PR for this.

ndarilek commented 1 year ago

So I guess this is now fixed with the merged PR? Please reopen if not.

Thanks!

helgoboss commented 1 year ago

Ah thanks, yes. It's fixed.