iOS 0.1.2: plugin check can't crash on a stale registration after an update

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Reactorcoremeltdown
2026-11-14 21:10:05 +01:00
co-authored by Claude Opus 5.5
parent 7d8311a77f
commit 005e0984de
3 changed files with 41 additions and 3 deletions
+32 -1
View File
@@ -40,6 +40,26 @@ final class PluginCheck: ObservableObject {
lines.append("\(ok)/\(comps.count) passed")
}
/// Loads a plugin out of process without ever crashing the app. Right after an
/// update, iOS may still list the old registration while the new one isn't
/// resolvable yet; AVAudioUnit.instantiate then raises an Objective-C
/// exception ("comp != NULL") instead of returning an error.
private func instantiate(_ desc: AudioComponentDescription) async throws -> AVAudioUnit {
var d = desc
guard AudioComponentFindNext(nil, &d) != nil else { throw CheckError.notRegistered }
return try await withCheckedThrowingContinuation { cont in
var resumed = false
let ex = SPKTry {
AVAudioUnit.instantiate(with: d, options: .loadOutOfProcess) { unit, error in
if let unit = unit { cont.resume(returning: unit) }
else { cont.resume(throwing: error ?? CheckError.notRegistered) }
}
resumed = true
}
if let ex = ex, !resumed { cont.resume(throwing: CheckError.exception(ex)) }
}
}
/// 1 s at 44.1 kHz stereo: a decaying saw burst, then noise, then silence.
private func testBuffer(format: AVAudioFormat) -> AVAudioPCMBuffer {
let n = AVAudioFrameCount(format.sampleRate)
@@ -58,7 +78,7 @@ final class PluginCheck: ObservableObject {
private func check(_ comp: AVAudioUnitComponent) async -> String {
do {
let unit = try await AVAudioUnit.instantiate(with: comp.audioComponentDescription, options: .loadOutOfProcess)
let unit = try await instantiate(comp.audioComponentDescription)
let engine = AVAudioEngine()
let format = AVAudioFormat(standardFormatWithSampleRate: 44_100, channels: 2)!
let player = AVAudioPlayerNode()
@@ -95,3 +115,14 @@ final class PluginCheck: ObservableObject {
}
}
}
enum CheckError: LocalizedError {
case notRegistered
case exception(String)
var errorDescription: String? {
switch self {
case .notRegistered: return "not registered (yet): reopen the app, or restart the iPad after an update"
case .exception(let e): return "exception \(e)"
}
}
}