2

I have a SwiftUI view that uses a PKCanvasView However, I am receiving an error in the logs

2023-05-07 01:06:14.413211-0700 [24247:15704822] Metal API Validation Enabled

2023-05-07 01:06:16.157795-0700 [24247:15705030] [] Failed to allocate an IOSurface, falling back to a regular framebuffer to avoid crashing.

2023-05-07 01:06:18.096437-0700 [24247:15704904] [] Failed to allocate an IOSurface, falling back to a regular framebuffer to avoid crashing.

here's my CanvasView

struct DrawingCanvasView: UIViewRepresentable {
    @Binding var canvas: PKCanvasView
    let drawingPolicy: PKCanvasViewDrawingPolicy

    func makeUIView(context: Context) -> PKCanvasView {
        canvas.drawingPolicy = drawingPolicy
        return canvas
    }

    func updateUIView(_ uiView: PKCanvasView, context: Context) {

    }
}

and here's the view

struct ExpereinceDrawingContentView: View {
    @ObservedObject private var viewModel: ExperienceDrawingContentViewModel

    init(viewModel: ExperienceDrawingContentViewModel) {
        self.viewModel = viewModel
    }

    var body: some View {
        DrawingCanvasView(canvas: $viewModel.canvas, drawingPolicy: .anyInput)
            .onAppear(perform: viewModel.handleViewDidLoad)
            .navigationTitle("Draw")
            .toolbar {
                Button("Done") {
                    viewModel.handleDone()
                }
            }
    }
}

here's what's happening in the UI

enter image description here

Bas H
  • 2,114
  • 10
  • 14
  • 23
Blacksmith
  • 199
  • 7
  • 1
    I see similar. Only, after getting the metal API error the drawing view doesn't render unless I am actively drawing. When I draw I see it. When I do not draw, no drawing is visible. However, on device it behaves as expected. – Brian Trzupek May 07 '23 at 13:48

0 Answers0