diff --git a/Memola/Canvas/Contexts/GraphicContext.swift b/Memola/Canvas/Contexts/GraphicContext.swift index a0f28b2..ebf6c3e 100644 --- a/Memola/Canvas/Contexts/GraphicContext.swift +++ b/Memola/Canvas/Contexts/GraphicContext.swift @@ -29,7 +29,7 @@ final class GraphicContext: @unchecked Sendable { var erasers: [URL: EraserStroke] = [:] - let concurrentQueue = DispatchQueue(label: "com.dispatchBarrier", attributes: .concurrent) + let barrierQueue = DispatchQueue(label: "com.memola.app.graphic-context", attributes: .concurrent) init() { setViewPortVertices() diff --git a/Memola/Canvas/Geometries/Stroke/Strokes/PenStroke.swift b/Memola/Canvas/Geometries/Stroke/Strokes/PenStroke.swift index 6eb9c62..2bdd8b8 100644 --- a/Memola/Canvas/Geometries/Stroke/Strokes/PenStroke.swift +++ b/Memola/Canvas/Geometries/Stroke/Strokes/PenStroke.swift @@ -84,7 +84,7 @@ final class PenStroke: Stroke, @unchecked Sendable { eraserStrokes = Set(object.erasers.compactMap { [graphicContext] eraser -> EraserStroke? in guard let eraser = eraser as? EraserObject else { return nil } let url = eraser.objectID.uriRepresentation() - return graphicContext.concurrentQueue.sync(flags: .barrier) { + return graphicContext.barrierQueue.sync(flags: .barrier) { if graphicContext.erasers[url] == nil { let _stroke = EraserStroke(object: eraser) _stroke.loadQuads(from: eraser) diff --git a/Memola/Canvas/RenderPasses/GraphicRenderPass.swift b/Memola/Canvas/RenderPasses/GraphicRenderPass.swift index 45b30ff..f798406 100644 --- a/Memola/Canvas/RenderPasses/GraphicRenderPass.swift +++ b/Memola/Canvas/RenderPasses/GraphicRenderPass.swift @@ -100,5 +100,18 @@ class GraphicRenderPass: RenderPass { } graphicContext.previousStroke = nil } + + let eraserStrokes = graphicContext.eraserStrokes + for eraserStroke in eraserStrokes { + if eraserStroke.finishesSaving { + graphicContext.eraserStrokes.remove(eraserStroke) + continue + } + descriptor.colorAttachments[0].loadAction = clearsTexture ? .clear : .load + clearsTexture = false + eraserRenderPass.stroke = eraserStroke + eraserRenderPass.descriptor = descriptor + eraserRenderPass.draw(on: canvas, with: renderer) + } } }