pyobjc icon indicating copy to clipboard operation
pyobjc copied to clipboard

Segmentation fault with AudioHardwareCreateAggregateDevice

Open TnTora opened this issue 10 months ago • 0 comments

Describe the bug Calling AudioHardwareCreateAggregateDevice from the CoreAudio framework results in a segmentation fault

Platform information

  • Python 3.13.1
  • installed via homebrew
  • macOS 15.2 (x86)

To Reproduce

import CoreAudio
aggregate_device_properties = {
    CoreAudio.kAudioAggregateDeviceNameKey: "TestAggregateDevice",
    CoreAudio.kAudioAggregateDeviceUIDKey: "com.user.TestAggregateDevice",
}
stat, aggr_id = CoreAudio.AudioHardwareCreateAggregateDevice(aggregate_device_properties, None)
print(f"aggr_id: {aggr_id}")
CoreAudio.AudioHardwareDestroyAggregateDevice(aggr_id)

Expected behavior Give the same result as the following code

#include <CoreAudio/AudioHardware.h>
#include <CoreAudio/CoreAudio.h>
#include <Foundation/Foundation.h>

int main() {
    OSStatus status;
    AudioObjectID aggregate_device_id = 0;
    NSDictionary* aggregate_device_properties = nil;

    aggregate_device_properties = @{
        @kAudioAggregateDeviceNameKey : @"TestAggregateDevice",
        @kAudioAggregateDeviceUIDKey :
            @"com.user.TestAggregateDevice",
    };

    status = AudioHardwareCreateAggregateDevice(
        (CFDictionaryRef)aggregate_device_properties, &aggregate_device_id);

    printf("aggr_id: %u\n", aggregate_device_id);
    
    AudioHardwareDestroyAggregateDevice(aggregate_device_id);
}

Additional context I'm trying to replicate some of the functionality of this code.

And here is the output from lldb

2025-02-24 03:57:27.136499+0100 Python[46773:4645070] [plugin] AddInstanceForFactory: No factory registered for id <CFUUID 0x600001f54540> F8BB1C28-BAE8-11D6-9C31-00039315CD46
2025-02-24 03:57:27.214072+0100 Python[46773:4645070]       HALC_ShellObject.mm:615    HALC_ShellObject::SetPropertyData: call to the proxy failed, Error: 1852797029 (nope)
2025-02-24 03:57:27.214346+0100 Python[46773:4645070]       HALC_ShellObject.mm:615    HALC_ShellObject::SetPropertyData: call to the proxy failed, Error: 1852797029 (nope)
2025-02-24 03:57:27.214566+0100 Python[46773:4645070]       HALC_ShellObject.mm:615    HALC_ShellObject::SetPropertyData: call to the proxy failed, Error: 1852797029 (nope)
Process 46773 stopped
* thread #2, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
    frame #0: 0x00007ff8158ac37c CoreFoundation`CF_IS_OBJC + 12
CoreFoundation`CF_IS_OBJC:
->  0x7ff8158ac37c <+12>: movq   (%rsi), %rcx
    0x7ff8158ac37f <+15>: testq  %rcx, %rcx
    0x7ff8158ac382 <+18>: je     0x7ff8158ac3a2 ; <+50>
    0x7ff8158ac384 <+20>: cmpq   $0x7, %rdi
Target 0: (Python) stopped.
(lldb) thread backtrace 
* thread #2, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
  * frame #0: 0x00007ff8158ac37c CoreFoundation`CF_IS_OBJC + 12
    frame #1: 0x00007ff8157834d1 CoreFoundation`CFDataGetBytePtr + 22
    frame #2: 0x00007ff818040702 CoreAudio`HALC_ShellPlugIn::CreateAggregateDevice(__CFDictionary const*, unsigned int&) + 128
    frame #3: 0x00007ff818117c71 CoreAudio`AudioHardwareCreateAggregateDevice_mac_imp + 81
    frame #4: 0x00007ff827d2c882 libffi.dylib`ffi_call_unix64 + 82
    frame #5: 0x00007ff827d2c1fb libffi.dylib`ffi_call_int + 805
    frame #6: 0x000000010034e2f3 _objc.cpython-313-darwin.so`func_vectorcall + 1283
    frame #7: 0x000000010054a82a Python`PyObject_Vectorcall + 75
    frame #8: 0x000000010067eaf7 Python`_PyEval_EvalFrameDefault + 11631
    frame #9: 0x000000010067bbdf Python`PyEval_EvalCode + 207
    frame #10: 0x00000001006f1e25 Python`run_eval_code_obj + 97
    frame #11: 0x00000001006f17c7 Python`run_mod + 154
    frame #12: 0x00000001006f0039 Python`pyrun_file + 141
    frame #13: 0x00000001006ef454 Python`_PyRun_SimpleFileObject + 272
    frame #14: 0x00000001006ef114 Python`_PyRun_AnyFileObject + 66
    frame #15: 0x0000000100717dbd Python`pymain_run_file_obj + 187
    frame #16: 0x0000000100717aa7 Python`pymain_run_file + 94
    frame #17: 0x0000000100716c01 Python`Py_RunMain + 1263
    frame #18: 0x00000001007172c9 Python`pymain_main + 371
    frame #19: 0x000000010071737c Python`Py_BytesMain + 42
    frame #20: 0x00007ff81536e2cd dyld`start + 1805

TnTora avatar Feb 24 '25 03:02 TnTora