XCPreviewAgent crashed with some SwiftUI View

The steps to reproduce this issue are a bit complicated.

In my app, previewing View A in Package P works fine, but another view in the same package fails to preview.

The error message is shown below. It seems that the memory used for the preview is interfering with the shared memory area.

This is reported as FB18519266

Exception Subtype: KERN_PROTECTION_FAILURE at 0x00000003402d8900
Exception Codes: 0x0000000000000002, 0x00000003402d8900
VM Region Info: 0x3402d8900 is in 0x3402c8000-0x340a18000;  bytes after start: 67840  bytes before end: 7599871
      REGION TYPE                    START - END         [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      mapped file                 3401dc000-3402c8000    [  944K] r-x/rwx SM=COW  Object_id=57e4ac
--->  shared memory               3402c8000-340a18000    [ 7488K] rw-/rw- SM=SHM  
      mapped file                 340a18000-340f38000    [ 5248K] r-x/rwx SM=COW  Object_id=1dc9a049
Termination Reason: ****** 10 Bus error: 10
Terminating Process: exc handler [94787]

Hi,

Thank you for filing the feedback. It looks like you are exposing a bug, but we are having trouble reproducing this. Would you be able to attach your/a project to the feedback that you see this issue in?

As I mentioned, within the same package, preview works for a file in one target, but a file in another target throws the error mentioned above. It seems like a memory violation issue, but it's been difficult to find a reliable way to reproduce it. We'd like to share our code, but due to security constraints, that's not easy. We're looking for an alternative way to reproduce the issue. Are there any plans to fix memory-related preview issues in Beta 5?

Hi,

For your information, in Xcode 26 beta 5, the crash report provides some interesting new information.

The crash occurred same with 'shared memory'

Exception Subtype: KERN_PROTECTION_FAILURE at 0x000000038851ffd0
Exception Codes: 0x0000000000000002, 0x000000038851ffd0
VM Region Info: 0x38851ffd0 is in 0x38850c000-0x389a0c000;  bytes after start: 81872  bytes before end: 21938223
      REGION TYPE                    START - END         [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      shared memory               3884fc000-38850c000    [   64K] rw-/rw- SM=SHM  
--->  shared memory               38850c000-389a0c000    [ 21.0M] rw-/rw- SM=SHM  
      mapped file                 389a0c000-38a8d8000    [ 14.8M] r-x/rwx SM=COW  Object_id=c949d43b
Termination Reason: SIGNAL 10 Bus error: 10
Terminating Process: exc handler [75426]

However, the crash point provides even more information.

0   ???                           	       0x38851ffd0 ???
1   RuntimeInternal               	       0x243f29ff8 _withConformanceCache(for:do:) + 240
2   ReflectionInternal            	       0x2428d7004 _typesThatConform(to:) + 148
3   PreviewsInjection             	       0x24178d7f0 0x241736000 + 358384
4   PreviewsServices              	       0x2418cf9a8 0x2418c6000 + 39336
5   PreviewsInjection             	       0x24174f0d9 0x241736000 + 102617
6   PreviewsServices              	       0x2418cf921 0x2418c6000 + 39201
7   PreviewsInjection             	       0x24178d295 0x241736000 + 357013
8   PreviewsInjection             	       0x241786141 0x241736000 + 328001
9   PreviewsInjection             	       0x241785bd1 0x241736000 + 326609
10  PreviewsInjection             	       0x24173f47d 0x241736000 + 38013
11  PreviewsInjection             	       0x241739475 0x241736000 + 13429
12  PreviewsInjection             	       0x241763325 0x241736000 + 185125
13  PreviewsInjection             	       0x24176a2d9 0x241736000 + 213721
14  PreviewsInjection             	       0x24176bb79 0x241736000 + 220025
15  PreviewsInjection             	       0x241739475 0x241736000 + 13429
16  PreviewsInjection             	       0x241739475 0x241736000 + 13429
17  libswift_Concurrency.dylib    	       0x258e99ee5 completeTaskWithClosure(swift::AsyncContext*, swift::SwiftError*) + 1
XCPreviewAgent crashed with some SwiftUI View
 
 
Q