From c2b39ba358d2ee2a420ea21e649c7b14587f832f Mon Sep 17 00:00:00 2001 From: dscyrescotti Date: Wed, 22 May 2024 21:37:55 +0700 Subject: [PATCH] bug: fix stroke glitching --- Memola/App/MemolaApp.swift | 5 ++ Memola/Canvas/Contexts/GraphicContext.swift | 6 ++- .../SolidPointStrokeGenerator.swift | 24 +++++++++- Memola/Canvas/Geometries/Stroke/Stroke.swift | 46 +++++++++++++------ Memola/Features/Memo/Toolbar/Toolbar.swift | 14 ++++-- 5 files changed, 75 insertions(+), 20 deletions(-) diff --git a/Memola/App/MemolaApp.swift b/Memola/App/MemolaApp.swift index 68edd1f..4804ebc 100644 --- a/Memola/App/MemolaApp.swift +++ b/Memola/App/MemolaApp.swift @@ -13,6 +13,11 @@ struct MemolaApp: App { WindowGroup { MemosView() .persistence(\.viewContext) + .onReceive(NotificationCenter.default.publisher(for: UIApplication.willTerminateNotification)) { _ in + withPersistenceSync(\.backgroundContext) { context in + try context.saveIfNeeded() + } + } } } } diff --git a/Memola/Canvas/Contexts/GraphicContext.swift b/Memola/Canvas/Contexts/GraphicContext.swift index 19b0a5f..576d44c 100644 --- a/Memola/Canvas/Contexts/GraphicContext.swift +++ b/Memola/Canvas/Contexts/GraphicContext.swift @@ -153,8 +153,10 @@ extension GraphicContext { func endStroke(at point: CGPoint) { guard currentPoint != nil, let currentStroke else { return } currentStroke.finish(at: point) - withPersistence(\.backgroundContext) { [currentStroke] context in - currentStroke.object?.bounds = currentStroke.bounds + let batchIndex = currentStroke.batchIndex + let quads = Array(currentStroke.quads[batchIndex..