Post

Replies

Boosts

Views

Activity

Reply to CATiledLayer flashes and re-draws entirely when re-drawing a single tile
I have not yet checked if the "redraws entire contents instead of specified rect" issue is still occurring. However, the "flashes on redraw" issue is still occurring with CATiledLayer in Xcode 26.6. The flash occurs even when returning 0 from CATiledLayer.fadeDuration(). It seems that each sublayer/tile of the CATiledLayer simply releases/erases its already-drawn contents before drawing the new contents. It would be nice to have the option to replace the existing drawing without erasing it first. This solution from @mgalijot: [quote='786127021, mgalijot, /thread/786127, /profile/mgalijot'] I have, however, found one interesting thing which seems to work so far: before calling setNeedsDisplayInRect (or just setNeedsDisplay, as they behave the same for CATiledLayer in my testing), cache the current layer's contents, and after calling setNeedsDisplay (or setNeedsDisplayInRect), restore the contents back to the layer. This prevents flashing and preserves any tiles that were drawn at the time of the re-draw. let c = tiledLayer.contents tiledLayer.setNeedsDisplay(tileRect) tiledLayer.contents = c [/quote] does fix the flash. Could an Apple engineer comment whether or not this is a valid workaround? Here's the relevant code I'm currently using (Swift 6): CATiledLayer subclass nonisolated final class NoFade_CATiledLayer: CATiledLayer { override class func fadeDuration() -> CFTimeInterval { 0 } } UIView layerClass override class var layerClass: AnyClass { NoFade_CATiledLayer.self } UIView draw(_:) /* This method must be marked "nonisolated" when it is called by "CATiledLayer" or one of its sublayers. Otherwise, the app crashes. */ nonisolated override func draw(_ rect: CGRect) { guard let cgContext = UIGraphicsGetCurrentContext() else { return } let cgPaths = cgPaths_Mutex.withLock { $0 } let fillColor = CGColor( srgbRed: 0.5, green: 0.5, blue: 0.5, alpha: 1 ) for cgPath in cgPaths { cgContext.addPath(cgPath) cgContext.setFillColor(fillColor) cgContext.fillPath() } } Calling setNeedsDisplay() private func onChange_cgPaths(newPaths: [CGPath]) { cgPaths_Mutex.withLock { (cgPaths: inout [CGPath]) -> Void in cgPaths = newPaths } setNeedsDisplay() }
Topic: UI Frameworks SubTopic: General Tags:
Jul ’26
Reply to SwiftData document-based app crashes on undo/redo without ModelContext.transaction(block:)
The issue is still occurring with Xcode 26.4.1 (17E202) and macOS Tahoe 26.4.1 (25E253). I also noticed that, rarely, the following errors get logged when the app crashes instead of the error in my original post: SwiftData.DefaultStore save failed with error: Error Domain=NSCocoaErrorDomain Code=1570 "%{PROPERTY}@ is a required value." UserInfo={NSValidationErrorObject=<NSManagedObject: 0x9da1b20d0> (entity: ChildItem; id: 0x9d7f324a0 <x-coredata:///ChildItem/tA0242788-AD81-4A4A-82BD-92796386C7E75>; data: { index = nil; parentItem = "0x9d7f32380 <x-coredata:///ParentItem/tA0242788-AD81-4A4A-82BD-92796386C7E73>"; }), NSLocalizedDescription=%{PROPERTY}@ is a required value., NSValidationErrorKey=index, NSValidationErrorValue=null} SwiftData/ModelContext.swift:3256: Fatal error: Illegal attempt to resolve a fault against a store that is not known to this model context: PersistentIdentifier(id: SwiftData.PersistentIdentifier.ID(backing: SwiftData.PersistentIdentifier.PersistentIdentifierBacking.managedObjectID(0x9d7f32380 <x-coredata:///ParentItem/tA0242788-AD81-4A4A-82BD-92796386C7E73>))) SwiftData.ModelContext Can't show source file for stack frame 8: ParentItem.childItems.getter The file path does not exist on the file system: /var/folders/sb/kvhs_53d49n1djmvf6jbf6lh0000gp/T/swift-generated-sources/@__swiftmacro_12DocumentTest10ParentItemC10childItems18_PersistedPropertyfMa_.swift However, I don't know how to reproduce these specific errors. They get logged randomly and rarely. Most of the time, the error in my original post gets logged.
Topic: App & System Services SubTopic: iCloud Tags:
Apr ’26
Reply to CATiledLayer flashes and re-draws entirely when re-drawing a single tile
I have not yet checked if the "redraws entire contents instead of specified rect" issue is still occurring. However, the "flashes on redraw" issue is still occurring with CATiledLayer in Xcode 26.6. The flash occurs even when returning 0 from CATiledLayer.fadeDuration(). It seems that each sublayer/tile of the CATiledLayer simply releases/erases its already-drawn contents before drawing the new contents. It would be nice to have the option to replace the existing drawing without erasing it first. This solution from @mgalijot: [quote='786127021, mgalijot, /thread/786127, /profile/mgalijot'] I have, however, found one interesting thing which seems to work so far: before calling setNeedsDisplayInRect (or just setNeedsDisplay, as they behave the same for CATiledLayer in my testing), cache the current layer's contents, and after calling setNeedsDisplay (or setNeedsDisplayInRect), restore the contents back to the layer. This prevents flashing and preserves any tiles that were drawn at the time of the re-draw. let c = tiledLayer.contents tiledLayer.setNeedsDisplay(tileRect) tiledLayer.contents = c [/quote] does fix the flash. Could an Apple engineer comment whether or not this is a valid workaround? Here's the relevant code I'm currently using (Swift 6): CATiledLayer subclass nonisolated final class NoFade_CATiledLayer: CATiledLayer { override class func fadeDuration() -> CFTimeInterval { 0 } } UIView layerClass override class var layerClass: AnyClass { NoFade_CATiledLayer.self } UIView draw(_:) /* This method must be marked "nonisolated" when it is called by "CATiledLayer" or one of its sublayers. Otherwise, the app crashes. */ nonisolated override func draw(_ rect: CGRect) { guard let cgContext = UIGraphicsGetCurrentContext() else { return } let cgPaths = cgPaths_Mutex.withLock { $0 } let fillColor = CGColor( srgbRed: 0.5, green: 0.5, blue: 0.5, alpha: 1 ) for cgPath in cgPaths { cgContext.addPath(cgPath) cgContext.setFillColor(fillColor) cgContext.fillPath() } } Calling setNeedsDisplay() private func onChange_cgPaths(newPaths: [CGPath]) { cgPaths_Mutex.withLock { (cgPaths: inout [CGPath]) -> Void in cgPaths = newPaths } setNeedsDisplay() }
Topic: UI Frameworks SubTopic: General Tags:
Replies
Boosts
Views
Activity
Jul ’26
Reply to SwiftData document-based app crashes on undo/redo without ModelContext.transaction(block:)
The issue is still occurring with Xcode 26.4.1 (17E202) and macOS Tahoe 26.4.1 (25E253). I also noticed that, rarely, the following errors get logged when the app crashes instead of the error in my original post: SwiftData.DefaultStore save failed with error: Error Domain=NSCocoaErrorDomain Code=1570 "%{PROPERTY}@ is a required value." UserInfo={NSValidationErrorObject=<NSManagedObject: 0x9da1b20d0> (entity: ChildItem; id: 0x9d7f324a0 <x-coredata:///ChildItem/tA0242788-AD81-4A4A-82BD-92796386C7E75>; data: { index = nil; parentItem = "0x9d7f32380 <x-coredata:///ParentItem/tA0242788-AD81-4A4A-82BD-92796386C7E73>"; }), NSLocalizedDescription=%{PROPERTY}@ is a required value., NSValidationErrorKey=index, NSValidationErrorValue=null} SwiftData/ModelContext.swift:3256: Fatal error: Illegal attempt to resolve a fault against a store that is not known to this model context: PersistentIdentifier(id: SwiftData.PersistentIdentifier.ID(backing: SwiftData.PersistentIdentifier.PersistentIdentifierBacking.managedObjectID(0x9d7f32380 <x-coredata:///ParentItem/tA0242788-AD81-4A4A-82BD-92796386C7E73>))) SwiftData.ModelContext Can't show source file for stack frame 8: ParentItem.childItems.getter The file path does not exist on the file system: /var/folders/sb/kvhs_53d49n1djmvf6jbf6lh0000gp/T/swift-generated-sources/@__swiftmacro_12DocumentTest10ParentItemC10childItems18_PersistedPropertyfMa_.swift However, I don't know how to reproduce these specific errors. They get logged randomly and rarely. Most of the time, the error in my original post gets logged.
Topic: App & System Services SubTopic: iCloud Tags:
Replies
Boosts
Views
Activity
Apr ’26
Reply to SwiftData document-based app crashes on undo/redo without ModelContext.transaction(block:)
Hi Ziqiao, I've filed it under FB22539495. Best, Omar
Topic: App & System Services SubTopic: iCloud Tags:
Replies
Boosts
Views
Activity
Apr ’26
Reply to SwiftData document-based app crashes on undo/redo with autosaveEnabled
Hi Ziqiao, I've filed it under FB22429615. I've also found some more potential bugs when using SwiftData, DocumentGroup, and UndoManager together. I'll try to document them over the coming days. Thanks, Omar
Topic: App & System Services SubTopic: iCloud Tags:
Replies
Boosts
Views
Activity
Apr ’26