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 @@ : 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..