From 2cfcfb01d799c6debf4f95fa3999467ff648f3e0 Mon Sep 17 00:00:00 2001 From: Stanislav Date: Mon, 27 Oct 2025 15:08:29 -0700 Subject: [PATCH 1/5] [App] Replace @UIApplicationMain with @main --- .../project.pbxproj | 19 +++++++++++++------ .../xcschemes/SceneDepthPointCloud.xcscheme | 2 +- SceneDepthPointCloud/AppDelegate.swift | 2 +- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/SceneDepthPointCloud.xcodeproj/project.pbxproj b/SceneDepthPointCloud.xcodeproj/project.pbxproj index 37a7de4..ebd6552 100644 --- a/SceneDepthPointCloud.xcodeproj/project.pbxproj +++ b/SceneDepthPointCloud.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 50; + objectVersion = 54; objects = { /* Begin PBXBuildFile section */ @@ -131,8 +131,9 @@ E73DD12524636FEF00D77039 /* Project object */ = { isa = PBXProject; attributes = { + BuildIndependentTargetsInParallel = YES; LastSwiftUpdateCheck = 1140; - LastUpgradeCheck = 1200; + LastUpgradeCheck = 2610; ORGANIZATIONNAME = Apple; TargetAttributes = { E73DD12C24636FEF00D77039 = { @@ -245,8 +246,10 @@ CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = dwarf; + DEVELOPMENT_TEAM = 58R9CYQKK2; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; + ENABLE_USER_SCRIPT_SANDBOXING = YES; GCC_C_LANGUAGE_STANDARD = gnu11; GCC_DYNAMIC_NO_PIC = NO; GCC_NO_COMMON_BLOCKS = YES; @@ -266,6 +269,7 @@ MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos.internal; + STRING_CATALOG_GENERATE_SYMBOLS = YES; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; }; @@ -308,8 +312,10 @@ CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + DEVELOPMENT_TEAM = 58R9CYQKK2; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_USER_SCRIPT_SANDBOXING = YES; GCC_C_LANGUAGE_STANDARD = gnu11; GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; @@ -322,6 +328,7 @@ MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; SDKROOT = iphoneos.internal; + STRING_CATALOG_GENERATE_SYMBOLS = YES; SWIFT_COMPILATION_MODE = wholemodule; SWIFT_OPTIMIZATION_LEVEL = "-O"; VALIDATE_PRODUCT = YES; @@ -337,8 +344,8 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; - DEVELOPMENT_TEAM = 52N826U726; INFOPLIST_FILE = SceneDepthPointCloud/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 26.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -349,7 +356,7 @@ PROVISIONING_PROFILE_SPECIFIER = ""; SDKROOT = iphoneos; SWIFT_OBJC_BRIDGING_HEADER = "SceneDepthPointCloud/SceneDepthPointCloud-Bridging-Header.h"; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -363,8 +370,8 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; - DEVELOPMENT_TEAM = 52N826U726; INFOPLIST_FILE = SceneDepthPointCloud/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 26.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -375,7 +382,7 @@ PROVISIONING_PROFILE_SPECIFIER = ""; SDKROOT = iphoneos; SWIFT_OBJC_BRIDGING_HEADER = "SceneDepthPointCloud/SceneDepthPointCloud-Bridging-Header.h"; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; diff --git a/SceneDepthPointCloud.xcodeproj/xcshareddata/xcschemes/SceneDepthPointCloud.xcscheme b/SceneDepthPointCloud.xcodeproj/xcshareddata/xcschemes/SceneDepthPointCloud.xcscheme index 9819cea..f057a4b 100644 --- a/SceneDepthPointCloud.xcodeproj/xcshareddata/xcschemes/SceneDepthPointCloud.xcscheme +++ b/SceneDepthPointCloud.xcodeproj/xcshareddata/xcschemes/SceneDepthPointCloud.xcscheme @@ -1,6 +1,6 @@ Date: Mon, 27 Oct 2025 15:23:32 -0700 Subject: [PATCH 2/5] [Fix] Clean build after adding @MainActor to ViewController --- SceneDepthPointCloud/ViewController.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SceneDepthPointCloud/ViewController.swift b/SceneDepthPointCloud/ViewController.swift index 8c3e06f..c3ac8bc 100644 --- a/SceneDepthPointCloud/ViewController.swift +++ b/SceneDepthPointCloud/ViewController.swift @@ -10,7 +10,8 @@ import Metal import MetalKit import ARKit -final class ViewController: UIViewController, ARSessionDelegate { +@MainActor +final class ViewController: UIViewController, @MainActor ARSessionDelegate { private let isUIEnabled = true private let confidenceControl = UISegmentedControl(items: ["Low", "Medium", "High"]) private let rgbRadiusSlider = UISlider() From 14075dd8cdbae65f49850d57344e978db85d9ba0 Mon Sep 17 00:00:00 2001 From: Stanislav Date: Mon, 27 Oct 2025 16:14:51 -0700 Subject: [PATCH 3/5] [Fix] Added @MainActor isolation for TaskDelegate and RenderDestinationProvider --- SceneDepthPointCloud/ViewController.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/SceneDepthPointCloud/ViewController.swift b/SceneDepthPointCloud/ViewController.swift index c3ac8bc..8b26575 100644 --- a/SceneDepthPointCloud/ViewController.swift +++ b/SceneDepthPointCloud/ViewController.swift @@ -216,7 +216,7 @@ final class ViewController: UIViewController, @MainActor ARSessionDelegate { } // update textlabel on tasks start/finish -extension ViewController: TaskDelegate { +extension ViewController: @MainActor TaskDelegate { func didStartTask() { self.taskNum += 1 updateTextLabel() @@ -227,6 +227,7 @@ extension ViewController: TaskDelegate { updateTextLabel() } + @MainActor private func updateTextLabel() { let text = " 1/\(self.renderer.pickFrames) of new frames \n Files saved \(self.completedTaskNum)/\(self.taskNum) " DispatchQueue.main.async { @@ -251,6 +252,7 @@ extension ViewController: MTKViewDelegate { // MARK: - RenderDestinationProvider +@MainActor protocol RenderDestinationProvider { var currentRenderPassDescriptor: MTLRenderPassDescriptor? { get } var currentDrawable: CAMetalDrawable? { get } @@ -259,6 +261,7 @@ protocol RenderDestinationProvider { var sampleCount: Int { get set } } +@MainActor extension MTKView: RenderDestinationProvider { } From 19c5a3a69110eae5f614a805536138131755863f Mon Sep 17 00:00:00 2001 From: Stanislav Date: Mon, 27 Oct 2025 16:51:00 -0700 Subject: [PATCH 4/5] [Fix] Make MetalBuffer assign APIs Element-typed and Swift 6 safe; safer MetalBuffer array initializer; honor resource options; rewrite assign(with:) for safe raw copy and Swift 6 compliance --- SceneDepthPointCloud/MetalBuffer.swift | 30 +++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/SceneDepthPointCloud/MetalBuffer.swift b/SceneDepthPointCloud/MetalBuffer.swift index 1522bab..981ed80 100644 --- a/SceneDepthPointCloud/MetalBuffer.swift +++ b/SceneDepthPointCloud/MetalBuffer.swift @@ -43,7 +43,16 @@ struct MetalBuffer: Resource { /// Initializes the buffer with the contents of the provided array. init(device: MTLDevice, array: [Element], index: UInt32, options: MTLResourceOptions = []) { - guard let buffer = device.makeBuffer(bytes: array, length: MemoryLayout.stride * array.count, options: .storageModeShared) else { + // Safely create a buffer from the array's raw bytes. This avoids forming an UnsafeRawPointer + // directly from `[Element]` which may contain references. + let length = MemoryLayout.stride * array.count + let created: MTLBuffer? = array.withUnsafeBytes { rawBuffer in + guard let base = rawBuffer.baseAddress, rawBuffer.count == length else { + return device.makeBuffer(length: length, options: options) + } + return device.makeBuffer(bytes: base, length: rawBuffer.count, options: options) + } + guard let buffer = created else { fatalError("Failed to create MTLBuffer") } self.buffer = buffer @@ -60,10 +69,25 @@ struct MetalBuffer: Resource { } /// Replaces the buffer's memory with the values in the array. - func assign(with array: [Element]) { + func assign(with array: [Element]) { let byteCount = array.count * stride precondition(byteCount == buffer.length, "Mismatch between the byte count of the array's contents and the MTLBuffer length.") - buffer.contents().copyMemory(from: array, byteCount: byteCount) + + // Safely copy from the array's raw bytes. Avoid forming an UnsafeRawPointer directly from `[Element]` + // because `Element` may contain references. + array.withUnsafeBytes { rawBuffer in + if let base = rawBuffer.baseAddress, rawBuffer.count == byteCount { + buffer.contents().copyMemory(from: base, byteCount: byteCount) + } else { + // If we cannot get a valid raw representation (e.g., Element contains references), + // fall back to per-element assignment to avoid undefined behavior. + for i in 0.. Date: Mon, 27 Oct 2025 17:02:20 -0700 Subject: [PATCH 5/5] [Fix] Annotate Renderer as @MainActor for Swift 6 actor isolation safety --- SceneDepthPointCloud/Renderer.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/SceneDepthPointCloud/Renderer.swift b/SceneDepthPointCloud/Renderer.swift index 0ff0d4f..418d752 100644 --- a/SceneDepthPointCloud/Renderer.swift +++ b/SceneDepthPointCloud/Renderer.swift @@ -11,6 +11,7 @@ import ARKit import Foundation import UIKit +@MainActor final class Renderer { // Whether recording is on public var isRecording = false; @@ -504,3 +505,4 @@ private extension Renderer { return flipYZ * matrix_float4x4(simd_quaternion(rotationAngle, Float3(0, 0, 1))) } } +