Crash and unrecognized mp4, jpeg filetypes on iOS 15.4 simulator devices running on M1 Mac?

I stumbled upon a really peculiar issue while running my application that features both a functionality to create image and video attachments from the user's photos and videos using the PHPicker* API and previewing said attachments using the QuickLook API:

Whenever I tap to open a photo (e.g. a JPEG) or a video (e.g. a MP4) using the QuickLook API, on an iPhone 13 15.4 simulator device on Xcode 13.3 on a M1 Macbook Pro host machine, I get a crash with the following call stack:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[2]'
terminating with uncaught exception of type NSException
*** First throw call stack:
(
	0   CoreFoundation                      0x000000011003bd44 __exceptionPreprocess + 242
	1   libobjc.A.dylib                     0x000000010cd1ea65 objc_exception_throw + 48
	2   CoreFoundation                      0x00000001100bcf47 _CFThrowFormattedException + 200
	3   CoreFoundation                      0x00000001100c7417 -[__NSPlaceholderDictionary initWithObjects:forKeys:count:].cold.5 + 0
	4   CoreFoundation                      0x00000001100aa827 -[__NSPlaceholderDictionary initWithObjects:forKeys:count:] + 243
	5   CoreFoundation                      0x000000011003a998 +[NSDictionary dictionaryWithObjects:forKeys:count:] + 49
	6   QuickLook                           0x0000000110f37636 __49+[QLItem(PreviewInfo) contentTypesToPreviewTypes]_block_invoke + 484
	7   libdispatch.dylib                   0x000000011b0f5a5b _dispatch_client_callout + 8
	8   libdispatch.dylib                   0x000000011b0f6f24 _dispatch_once_callout + 66
	9   QuickLook                           0x0000000110f37450 +[QLItem(PreviewInfo) contentTypesToPreviewTypes] + 46
	10  QuickLook                           0x0000000110f37d91 -[QLItem(PreviewInfo) _uncachedPreviewItemTypeForContentType:] + 117
	11  QuickLook                           0x0000000110f382fe -[QLItem(PreviewInfo) _previewItemTypeForType:] + 150
	12  QuickLook                           0x0000000110f38104 -[QLItem(PreviewInfo) _getPreviewItemType] + 61
	13  QuickLook                           0x0000000110fbf4d2 -[QLItem previewItemType] + 59
	14  QuickLook                           0x0000000110f6ed15 +[QLItemFetcherFactory fetcherForPreviewItem:] + 90
	15  QuickLook                           0x0000000110fbeb9b -[QLItem fetcher] + 44
	16  QuickLook                           0x0000000110f22880 -[QLPreviewController previewItemAtIndex:withCompletionHandler:] + 153
	17  QuickLook                           0x0000000110f587a8 __63-[QLPreviewItemStore previewItemAtIndex:withCompletionHandler:]_block_invoke + 262
	18  QuickLook                           0x0000000110f8c621 QLRunInMainThread + 51
	19  QuickLook                           0x0000000110f58673 -[QLPreviewItemStore previewItemAtIndex:withCompletionHandler:] + 181
	20  QuickLook                           0x0000000110f1c89f -[QLPreviewController internalCurrentPreviewItem] + 222
	21  QuickLook                           0x0000000110f9c140 -[QLPreviewController(Overlay) _actionButton] + 344
	22  QuickLook                           0x0000000110f9c81c -[QLPreviewController(Overlay) _toolBarButtonsWithTraitCollection:] + 1147
	23  QuickLook                           0x0000000110f9a2ff -[QLPreviewController(Overlay) _updateOverlayButtonsIfNeededWithTraitCollection:animated:updatedToolbarButtons:] + 129
	24  QuickLook                           0x0000000110f999a2 -[QLPreviewController(Overlay) updateOverlayAnimated:animatedButtons:forceRefresh:withTraitCollection:] + 152
	25  QuickLook                           0x0000000110f1c707 -[QLPreviewController _setCurrentPreviewItemIndex:updatePreview:animated:] + 230
	26  QuickLook                           0x0000000110f22416 -[QLPreviewController reloadData] + 418
	27  <MYAPP>                             0x0000000102a03293 __53-[MyPreviewController downloadAttachment]_block_invoke_2 + 611
	28  libdispatch.dylib                   0x000000011b0f4816 _dispatch_call_block_and_release + 12
	29  libdispatch.dylib                   0x000000011b0f5a5b _dispatch_client_callout + 8
	30  libdispatch.dylib                   0x000000011b104325 _dispatch_main_queue_drain + 1169
	31  libdispatch.dylib                   0x000000011b103e86 _dispatch_main_queue_callback_4CF + 31
	32  CoreFoundation                      0x000000010ffa8261 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
	33  CoreFoundation                      0x000000010ffa2a56 __CFRunLoopRun + 2761
	34  CoreFoundation                      0x000000010ffa1a90 CFRunLoopRunSpecific + 562
	35  GraphicsServices                    0x00000001209c8c8e GSEventRunModal + 139
	36  UIKitCore                           0x000000013499c90e -[UIApplication _run] + 928
	37  UIKitCore                           0x00000001349a1569 UIApplicationMain + 101
	38  <MYAPP>                             0x0000000102970669 main + 233
	39  dyld                                0x000000010c6c4f21 start_sim + 10
	40  ???                                 0x00000002041ad51e 0x0 + 8658801950
	41  ???                                 0x0000000000000003 0x0 + 3

I tried also selecting a photo or a video using the PHPicker* APIs, and although I get back the file, if I try to query the UTType from the file extension using the [UTType typeWithFilenameExtension:] method, I get back a nil result if the extension passed is either a "jpeg" or a "mp4".

The above do not happen if I run the same simulator (iPhone 13 15.4 / Xcode 13.3) on an Intel Macbook Pro host machine, or on a real device.

Any ideas?

I get a crash with the following call stack:

Please post the full crash report. See Posting a Crash Report for advice on how to do that.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Hey Quinn! I am attaching the full crash report in this answer:

The same with me

I am attaching the full crash report

Thanks!

That crash report indicates that you have a third-party crash reporter in play, something called Sentry. If so, please remove it [1], re-test, and, if it still crashes, post an updated crash report.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] … temporarily. Well, actually, I’d be happier if you removed it permanently. See my Implementing Your Own Crash Reporter post for an explanation of why.

Hello Quinn, I have temporarily removed Sentry, re-tested and it still crashes. Please find the updated crash report attached.

Thanks for the updated crash report.

Consider this:

Hardware Model:      MacBookPro18,3

and this:

Thread 0 crashed with X86 Thread State (64-bit):

I believe that MacBookPro18,3 indicates a MacBook Pro (14-inch, 2021), that is, an Apple silicon Mac. But you’re running Intel code, meaning that you must be running the simulator under Rosetta. That’s not a supported configuration. Please re-test running the simulator natively.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I believe you are right. My host machine is indeed a Macbook Pro (14-inch, 2021) that has the M1 family chip.

On my Xcode project, I was excluding the "arm64" architecture for the simulator devices due to some old dependencies via the "EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64; flag.

As far as I can understand, this was triggering the simulator processes to spawn under Rosetta emulation, although this was not shown somewhere. Even the Activity Monitor window displayed 'Apple' instead of 'Intel' in the 'Kind' column:

When I removed the "EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64; flag, adjusted my dependencies and re-run the app on the Simulator, I was able to open the QuickLook preview controller without a crash, so I assume that this flag was to blame here.

As a general question, is there a way to know whether the simulator instance runs under Rosetta emulation?

I was excluding the arm64 architecture

Ah, yes, that chestnut. Issues like this are common, so one of my colleagues created a technote that covers this topic in depth: TN3117 Resolving architecture build errors on Apple silicon.

is there a way to know whether the simulator instance runs under Rosetta emulation?

I suspect it’s not the simulator that’s running under Rosetta but your app within the simulator. If you undo your fix and look at your app in Activity Monitor, what do you see?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

If you undo your fix and look at your app in Activity Monitor, what do you see?

You are right: The iOS app shows up as 'Intel' kind in the Activity Monitor while the Simulator app shows up as 'Apple' kind.

Thanks Quinn!

Crash and unrecognized mp4, jpeg filetypes on iOS 15.4 simulator devices running on M1 Mac?
 
 
Q