Skip to content

macOS render errors when resizing window (AudioQueueObject.cpp:3329) #104

@erin-dot-io

Description

@erin-dot-io

When trying to render a waveform in a macOS app, I'm getting errors that seem to be related to the window size. When the app first builds and launches from Xcode, the waveform renders correctly. As soon as I begin to resize the window however, the error occurs repeatedly and the waveform either takes a long time to re-render (5-10 seconds or more) or doesn't re-render at all. Sometimes the waveform re-renders at the correct size, but often it does not.

The initial error I get when building is:
AddInstanceForFactory: No factory registered for id <CFUUID 0x60000305e4e0> F8BB1C28-BAE8-11D6-9C31-00039315CD46

And then this error 3 times:
AudioQueueObject.cpp:3329 _Start: Error (-4) getting reporterIDs

When I resize the window width, I get the above error a bunch of times, 10-20 or more, before the waveform eventually re-renders.

Here's my code:

import DSWaveformImage
import DSWaveformImageViews
import SwiftUI

struct ProgressWaveformView: View {
    let audioURL: URL
    let progress: Double
    let lineWidth = 3.0
        
    var body: some View {
        GeometryReader { geometry in
            WaveformView(audioURL: audioURL, configuration: .init(style: .striped(.init(color: .black, width: lineWidth, spacing: lineWidth / 3)))) { shape in
                shape.stroke(LinearGradient(colors: [.yellow, .green], startPoint: .top, endPoint: .bottom), lineWidth: lineWidth / 2).mask(alignment: .leading) {
                    Rectangle().frame(width: geometry.size.width)
                }
                shape.stroke(LinearGradient(colors: [.green, .yellow], startPoint: .top, endPoint: .bottom), lineWidth: lineWidth).mask(alignment: .leading) {
                    Rectangle().frame(width: geometry.size.width * progress)
                }
            }
        }
    }
}

struct ContentView: View {
    private let audioURL = Bundle.main.url(forResource: "ExampleTrack", withExtension: "mp3")!
    @State private var progress: Double = .random(in: 0...1)

    var body: some View {
        VStack {
            ProgressWaveformView(audioURL: audioURL, progress: progress)

            Button(action: { withAnimation { progress = .random(in: 0...1) }}) {
                Label("Progress", systemImage: "dice.fill")
            }.buttonStyle(.borderedProminent)
        }
        .padding()
    }
}

Here's what this looks like in the preview:
CleanShot 2024-10-08 at 18 37 37@2x

And when I build & run locally, initially it will look something like this:
CleanShot 2024-10-08 at 18 40 42@2x

Resizing the window larger looks like this for 10-30 seconds, sometimes never re-rendering:
CleanShot 2024-10-08 at 18 41 12@2x

When quitting and reopening or rerunning the app from Xcode, sometimes the waveform is the correct width, and sometimes it's still sized incorrectly.

Any idea what's going on here? My skills are quite junior in Swift/SwiftUI (long time UX designer learning to code here!) so fully prepared to accept that it's something dumb that I overlooked.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions