Skip to content

Fix iOS 26 crash in AudioUnitMIDISynth soundfont load#51

Open
x-sti wants to merge 1 commit intorodydavis:masterfrom
x-sti:fix/ios-26-soundfont-crash
Open

Fix iOS 26 crash in AudioUnitMIDISynth soundfont load#51
x-sti wants to merge 1 commit intorodydavis:masterfrom
x-sti:fix/ios-26-soundfont-crash

Conversation

@x-sti
Copy link

@x-sti x-sti commented Dec 28, 2025

When trying to use an SF2 soundfont, the following happens:

Unrecognized selector -[Foundation._SwiftURL baseURL]
CoreSimulator 1051.17.7 - Device: iPhone 16e (CD430125-582A-404C-AA12-E4C8BE3FFF63) - Runtime: iOS 26.2 (23C54) - DeviceType: iPhone 16e

This is happening in the following stack in the AudioUnitMIDISynth class:

AudioUnitSetProperty()
loadMIDISynthSoundFont()
prepare()
init()
The reason seems to be that Swift in iOS 26 has changed the transformation of URL to pointers. See description here: https://stackoverflow.com/questions/78371703/is-swift-5-10-warning-about-likely-incorrect-actually-incorrect-for-optional

Proposed transformation:
current code:
let status = AudioUnitSetProperty( self.midisynthUnit!, AudioUnitPropertyID(kMusicDeviceProperty_SoundBankURL), AudioUnitScope(kAudioUnitScope_Global), 0, &bankURL, UInt32(MemoryLayout.size))
new code:
withUnsafePointer(to: bankURL as CFURL) { let status = AudioUnitSetProperty( self.midisynthUnit!, AudioUnitPropertyID(kMusicDeviceProperty_SoundBankURL), AudioUnitScope(kAudioUnitScope_Global), 0, $0, UInt32(MemoryLayout.size(ofValue: bankURL)) )

Tested and works fine in Simulator with iPhone 16e.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant