iOS App crashes while converting CVPixelbuffer to JPG

I have been seeing some crash reports for my app on some devices (not all of them). The crash occurs while converting a CVPixelBuffer captured from Video to a JPG using VTCreateCGImageFromCVPixelBuffer from VideoToolBox. I have not been able to reproduce the crash on local devices, even under adverse memory conditions (many apps running in the background).

The field crash reports show that VTCreateCGImageFromCVPixelBuffer does the conversion in another thread and that thread crashed at call to vConvert_420Yp8_CbCr8ToARGB8888_vec.

Any suggestions on how to debug this further would be helpful.

Answered by MPDroid in 786717022

Since the original post, changed the approach to create the JPEG image - used CIContext instead of VideoToolbox

      let colorSpace = CGColorSpace(name: CGColorSpace.sRGB)
      let jpeg = ciContext.jpegRepresentation(of: CIImage(cvPixelBuffer: pixelBuffer), colorSpace: colorSpace!) 

It was still crashing. Attached is a crash log from using the CIContext approach.

Incident Identifier: 40F7E148-54D4-42B8-8159-C6B7607B59A7
Distributor ID:      com.apple.TestFlight
Hardware Model:      iPhone16,1
Process:             EEEE [1111]
Path:                /private/var/containers/Bundle/Application/4B3964E4-0144-46D7-A7C5-2C60EADD528E/EEEE.app/EEEE
Identifier:          com.www.EEEE
Version:             1.11 (13)
AppStoreTools:       15E204
AppVariant:          1:iPhone16,1:17.4
Beta:                YES
Code Type:           ARM-64 (Native)
Role:                Foreground
Parent Process:      launchd [1]
Coalition:           com.www.EEEE [1504]

Date/Time:           2024-04-30 20:06:22.6123 -0500
Launch Time:         2024-04-30 20:05:50.9456 -0500
OS Version:          iPhone OS 17.4.1 (21E236)
Release Type:        User
Baseband Version:    1.55.04
Report Version:      104

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x000000015bc78000
Exception Codes: 0x0000000000000001, 0x000000015bc78000
VM Region Info: 0x15bc78000 is not in any region.  Bytes after previous region: 1  Bytes before following region: 65536
      REGION TYPE                 START - END      [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      MALLOC_LARGE             15b1bc000-15bc78000 [ 10.7M] rw-/rwx SM=PRV  
--->  GAP OF 0x10000 BYTES
      MALLOC_LARGE             15bc88000-15bc98000 [   64K] rw-/rwx SM=PRV  
Termination Reason: SIGNAL 11 Segmentation fault: 11
Terminating Process: exc handler [6561]

Triggered by Thread:  6


Thread 0 name:
Thread 0:
0   libsystem_kernel.dylib        	0x00000001d9eb5af8 mach_msg2_trap + 8
1   libsystem_kernel.dylib        	0x00000001d9eb5890 mach_msg2_internal + 80 (mach_msg.c:201)
2   libsystem_kernel.dylib        	0x00000001d9eb57a8 mach_msg_overwrite + 436 (mach_msg.c:0)
3   libsystem_kernel.dylib        	0x00000001d9eb55e8 mach_msg + 24 (mach_msg.c:323)
4   CoreFoundation                	0x000000019199001c __CFRunLoopServiceMachPort + 160 (CFRunLoop.c:2624)
5   CoreFoundation                	0x000000019198df04 __CFRunLoopRun + 1208 (CFRunLoop.c:3007)
6   CoreFoundation                	0x000000019198d968 CFRunLoopRunSpecific + 608 (CFRunLoop.c:3420)
7   GraphicsServices              	0x00000001d5c834e0 GSEventRunModal + 164 (GSEvent.c:2196)
8   UIKitCore                     	0x0000000193e00edc -[UIApplication _run] + 888 (UIApplication.m:3692)
9   UIKitCore                     	0x0000000193e00518 UIApplicationMain + 340 (UIApplication.m:5282)
10  SwiftUI                       	0x00000001967c7860 closure #1 in KitRendererCommon(_:) + 168 (UIKitApp.swift:51)
11  SwiftUI                       	0x00000001967c76a8 runApp<a>(_:) + 152 (UIKitApp.swift:14)
12  SwiftUI                       	0x00000001963e39fc static App.main() + 132 (App.swift:114)
13  EEEE                          	0x00000001007bd260 static EEEEApp.$main() + 52 (EEEEApp.swift:0)
14  EEEE                          	0x00000001007bd260 main + 64
15  dyld                          	0x00000001b4eaed84 start + 2240 (dyldMain.cpp:1298)

Thread 1:
0   libsystem_pthread.dylib       	0x00000001ed93cfb8 start_wqthread + 0

Thread 2:
0   libsystem_pthread.dylib       	0x00000001ed93cfb8 start_wqthread + 0

Thread 3:
0   libsystem_pthread.dylib       	0x00000001ed93cfb8 start_wqthread + 0

Thread 4 name:
Thread 4:
0   libsystem_kernel.dylib        	0x00000001d9eb654c kevent_id + 8
1   libdispatch.dylib             	0x00000001998797d4 _dispatch_kq_poll + 228 (event_kevent.c:760)
2   libdispatch.dylib             	0x000000019987a1bc _dispatch_event_loop_wait_for_ownership + 436 (event_kevent.c:2232)
3   libdispatch.dylib             	0x0000000199866594 __DISPATCH_WAIT_FOR_QUEUE__ + 340 (queue.c:1700)
4   libdispatch.dylib             	0x000000019986615c _dispatch_sync_f_slow + 148 (queue.c:1784)
5   CoreImage                     	0x00000001a21b5f4c GetSurfaceFromCacheAndFill + 428 (surface-cache.cpp:1190)
6   CoreImage                     	0x00000001a21a1e44 CI::ProviderNode::surfaceForROI(CI::Context const*, CGRect const&) const + 992 (node-provider.cpp:453)
7   CoreImage                     	0x00000001a1f9b6ac CI::Context::bind_sampler(CI::TextureSampler const*, CI::roiKey const&, int, CI::KernelArgumentType, CI::TileTask*) + 1124 (context.cpp:795)
8   CoreImage                     	0x00000001a1f79fa0 CI::MetalContext::bind_arguments(CI::ProgramNode const*, CGRect const&, CGRect const&, CGSize const&, CI::TileTask*) + 1280 (context-metal.mm:2027)
9   CoreImage                     	0x00000001a1f796cc CI::MetalContext::render_node(CI::TileTask*, CI::ProgramNode*, CGRect const&, CGRect const&, void const**, __IOSurface**, unsigned long) + 1044 (context-metal.mm:1508)
10  CoreImage                     	0x00000001a1f97490 CI::MetalContext::render_root_node(CI::TileTask*, CI::ProgramNode*, CGRect const&, void () block_pointer, void () block_pointer) + 596 (context-metal.mm:1598)
11  CoreImage                     	0x00000001a1f7814c CI::Context::recursive_render(CI::TileTask*, CI::roiKey const&, CI::Node*, bool) + 2244 (context.cpp:514)
12  CoreImage                     	0x00000001a1f77870 CI::Context::render(CI::ProgramNode*, CGRect const&) + 176 (context.cpp:558)
13  CoreImage                     	0x00000001a1fa5144 invocation function for block in CI::image_render_to_surface(CI::Context*, CI::Image*, CGRect, __IOSurface*, CI::RenderDestination const*) + 72 (render.cpp:2784)
14  CoreImage                     	0x00000001a1f921a0 CI::recursive_tile(CI::RenderTask*, CI::Context*, CI::RenderDestination const*, char const*, CI::Node*, CGRect const&, CI::PixelFormat, CI::swizzle_info const&, CI::TileTask* (CI::ProgramNode*, CGR... + 4140 (render.cpp:2002)
15  CoreImage                     	0x00000001a1f90f8c CI::tile_node_graph(CI::Context*, CI::RenderDestination const*, char const*, CI::Node*, CGRect const&, CI::PixelFormat, CI::swizzle_info const&, CI::TileTask* (CI::ProgramNode*, CGRect) block_pointer) + 476 (render.cpp:2107)
16  CoreImage                     	0x00000001a1f90ac8 CI::image_render_to_surface(CI::Context*, CI::Image*, CGRect, __IOSurface*, CI::RenderDestination const*) + 2304 (render.cpp:2781)
17  CoreImage                     	0x00000001a1f8f40c -[CIContext(CIRenderDestination) _startTaskToRender:toDestination:forPrepareRender:forClear:error:] + 2076 (CIRenderDestination.mm:1966)
18  CoreImage                     	0x00000001a1f8ebd4 -[CIContext(CIRenderDestination) startTaskToRender:fromRect:toDestination:atPoint:error:] + 120 (CIRenderDestination.mm:1709)
19  CoreImage                     	0x00000001a1ff6560 invocation function for block in CI::copyIOSurfaceCallback(void*, CGImageProvider*, __CFDictionary const*) + 160 (CIContext_CGImage.mm:377)
20  libdispatch.dylib             	0x0000000199856dd4 _dispatch_client_callout + 20 (object.m:576)
21  libdispatch.dylib             	0x00000001998662c4 _dispatch_lane_barrier_sync_invoke_and_complete + 56 (queue.c:1100)
22  CoreImage                     	0x00000001a1ff6148 CI::copyIOSurfaceCallback(void*, CGImageProvider*, __CFDictionary const*) + 624 (CIContext_CGImage.mm:364)
23  ImageIO                       	0x0000000197683ad8 HEIFWritePlugin::writeImageAtIndex(IIOImagePixelDataProvider*, CGImage*, IIODictionary*, IIODictionary*, unsigned int) + 860 (HEIF_writePlugin.cpp:682)
24  ImageIO                       	0x0000000197686150 HEIFWritePlugin::writeAll() + 412 (HEIF_writePlugin.cpp:1526)
25  ImageIO                       	0x000000019766c5a0 IIO_Writer_HEIF::write(void*, void*) + 112 (HEIF_writer.cpp:130)
26  ImageIO                       	0x00000001976b9130 IIOImageDestination::finalizeDestination() + 896 (CGImageDestination.cpp:3559)
27  ImageIO                       	0x00000001976bb590 CGImageDestinationFinalize + 180 (CGImageDestination.cpp:4788)
28  CoreImage                     	0x00000001a1ff758c -[CIContext(ImageRepresentation) _dataRepresentationOfImage:UTIType:format:premultiplied:colorSpace:options:addAuxData:keysToMerge:error:] + 3828 (CIContext_ImageReps.mm:292)
29  CoreImage                     	0x00000001a1ff7e10 -[CIContext(ImageRepresentation) _JPEGRepresentationOfImage:colorSpace:options:error:] + 260 (CIContext_ImageReps.mm:662)
30  EEEE                          	0x00000001007aabe8 closure #1 in DataSet.addItem(name:pixelBuffer:source:save:ciContext:) + 472 (DataSetExtension.swift:124)
31  EEEE                          	0x00000001007b7b48 specialized autoreleasepool</a><a>(invoking:) + 56 (DataSetExtension.swift:109)
32  EEEE                          	0x00000001007b7b48 DataSet.addItem(name:pixelBuffer:source:save:ciContext:) + 56 (CameraProcessor.swift:0)
33  EEEE                          	0x00000001007b7b48 closure #1 in closure #5 in CameraProcessor.processCoreML(videoPixelBuffer:depthInfo:) + 420
34  EEEE                          	0x00000001007bc038 partial apply for closure #1 in closure #5 in CameraProcessor.processCoreML(videoPixelBuffer:depthInfo:) + 28 (:0)
35  EEEE                          	0x00000001007b9570 closure #1 in static ObjC.catchException(_:) + 36 (CameraProcessor.swift:417)
36  EEEE                          	0x00000001007bc07c thunk for @callee_guaranteed (@unowned AutoreleasingUnsafeMutablePointer?) -> () + 4 (:0)
37  EEEE                          	0x00000001007bc07c partial apply for thunk for @callee_guaranteed (@unowned AutoreleasingUnsafeMutablePointer?) -> () + 20
38  EEEE                          	0x00000001007b95d0 thunk for @escaping @callee_guaranteed (@unowned AutoreleasingUnsafeMutablePointer?) -> () + 24 (:0)
39  EEEE                          	0x00000001007a0044 +[ObjC catchException:error:] + 68 (ObjC.m:15)
40  EEEE                          	0x00000001007b84b8 static ObjC.catchException(_:) + 244 (CameraProcessor.swift:415)
41  EEEE                          	0x00000001007b77cc closure #5 in CameraProcessor.processCoreML(videoPixelBuffer:depthInfo:) + 292 (CameraProcessor.swift:190)
42  EEEE                          	0x00000001007dca34 thunk for @escaping @callee_guaranteed @Sendable () -> () + 28 (:0)
43  libdispatch.dylib             	0x000000019985513c _dispatch_call_block_and_release + 32 (init.c:1530)
44  libdispatch.dylib             	0x0000000199856dd4 _dispatch_client_callout + 20 (object.m:576)
45  libdispatch.dylib             	0x0000000199868a6c _dispatch_root_queue_drain + 864 (queue.c:7136)
46  libdispatch.dylib             	0x000000019986909c _dispatch_worker_thread2 + 156 (queue.c:7204)
47  libsystem_pthread.dylib       	0x00000001ed93cee4 _pthread_wqthread + 228 (pthread.c:2678)
48  libsystem_pthread.dylib       	0x00000001ed93cfc0 start_wqthread + 8

Thread 5:
0   libsystem_pthread.dylib       	0x00000001ed93cfb8 start_wqthread + 0

Thread 6 name:
Thread 6 Crashed:
0   libsystem_platform.dylib      	0x00000001ed886b1c _platform_memmove + 188
1   CoreImage                     	0x00000001a2075760 __42-[CIImage _initWithCVImageBuffer:options:]_block_invoke_2 + 72 (CIImage.mm:2683)
2   CoreImage                     	0x00000001a212fc34 PixelBufferApplyOnePlaneReadOnlyBlock + 312 (PixelBufferUtils.c:0)
3   CoreImage                     	0x00000001a20756f8 __42-[CIImage _initWithCVImageBuffer:options:]_block_invoke + 212 (CIImage.mm:2675)
4   CoreImage                     	0x00000001a21a2578 invocation function for block in CI::ProviderNode::surfaceForROI(CI::Context const*, CGRect const&) const + 248 (node-provider.cpp:390)
5   CoreImage                     	0x00000001a1f8cfd0 SurfaceApplyPlaneBlock + 404 (Surface.c:217)
6   CoreImage                     	0x00000001a21a2474 invocation function for block in CI::ProviderNode::surfaceForROI(CI::Context const*, CGRect const&) const + 120 (node-provider.cpp:364)
7   CoreImage                     	0x00000001a21b5a1c invocation function for block in CI::SurfaceCacheEntry::fillAsync() + 128 (surface-cache.cpp:359)
8   libdispatch.dylib             	0x000000019985513c _dispatch_call_block_and_release + 32 (init.c:1530)
9   libdispatch.dylib             	0x0000000199856dd4 _dispatch_client_callout + 20 (object.m:576)
10  libdispatch.dylib             	0x000000019985e400 _dispatch_lane_serial_drain + 748 (queue.c:3900)
11  libdispatch.dylib             	0x000000019985ef64 _dispatch_lane_invoke + 432 (queue.c:3991)
12  libdispatch.dylib             	0x0000000199869cb4 _dispatch_root_queue_drain_deferred_wlh + 288 (queue.c:6998)
13  libdispatch.dylib             	0x0000000199869528 _dispatch_workloop_worker_thread + 404 (queue.c:6592)
14  libsystem_pthread.dylib       	0x00000001ed93cf20 _pthread_wqthread + 288 (pthread.c:2665)
15  libsystem_pthread.dylib       	0x00000001ed93cfc0 start_wqthread + 8

Thread 7 name:
Thread 7:
0   libsystem_kernel.dylib        	0x00000001d9eb5af8 mach_msg2_trap + 8
1   libsystem_kernel.dylib        	0x00000001d9eb5890 mach_msg2_internal + 80 (mach_msg.c:201)
2   libsystem_kernel.dylib        	0x00000001d9eb57a8 mach_msg_overwrite + 436 (mach_msg.c:0)
3   libsystem_kernel.dylib        	0x00000001d9eb55e8 mach_msg + 24 (mach_msg.c:323)
4   CoreFoundation                	0x000000019199001c __CFRunLoopServiceMachPort + 160 (CFRunLoop.c:2624)
5   CoreFoundation                	0x000000019198df04 __CFRunLoopRun + 1208 (CFRunLoop.c:3007)
6   CoreFoundation                	0x000000019198d968 CFRunLoopRunSpecific + 608 (CFRunLoop.c:3420)
7   Foundation                    	0x000000019081c4a8 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 212 (NSRunLoop.m:373)
8   Foundation                    	0x00000001908464e8 -[NSRunLoop(NSRunLoop) runUntilDate:] + 64 (NSRunLoop.m:420)
9   UIKitCore                     	0x0000000193d63ac8 -[UIEventFetcher threadMain] + 420 (UIEventFetcher.m:1201)
10  Foundation                    	0x000000019088da9c __NSThread__start__ + 732 (NSThread.m:991)
11  libsystem_pthread.dylib       	0x00000001ed93da90 _pthread_start + 136 (pthread.c:927)
12  libsystem_pthread.dylib       	0x00000001ed93cfcc thread_start + 8

Thread 8:
0   libsystem_pthread.dylib       	0x00000001ed93cfb8 start_wqthread + 0

Thread 9 name:
Thread 9:
0   libsystem_kernel.dylib        	0x00000001d9eb5af8 mach_msg2_trap + 8
1   libsystem_kernel.dylib        	0x00000001d9eb5890 mach_msg2_internal + 80 (mach_msg.c:201)
2   libsystem_kernel.dylib        	0x00000001d9eb57a8 mach_msg_overwrite + 436 (mach_msg.c:0)
3   libsystem_kernel.dylib        	0x00000001d9eb55e8 mach_msg + 24 (mach_msg.c:323)
4   CoreFoundation                	0x000000019199001c __CFRunLoopServiceMachPort + 160 (CFRunLoop.c:2624)
5   CoreFoundation                	0x000000019198df04 __CFRunLoopRun + 1208 (CFRunLoop.c:3007)
6   CoreFoundation                	0x000000019198d968 CFRunLoopRunSpecific + 608 (CFRunLoop.c:3420)
7   CoreFoundation                	0x000000019198d6cc CFRunLoopRun + 64 (CFRunLoop.c:3446)
8   CoreMotion                    	0x000000019e95a3c0 CLMotionCore::runMotionThread(void*) + 1292 (CLMotionCore.mm:376)
9   libsystem_pthread.dylib       	0x00000001ed93da90 _pthread_start + 136 (pthread.c:927)
10  libsystem_pthread.dylib       	0x00000001ed93cfcc thread_start + 8

Thread 10 name:
Thread 10:
0   libsystem_kernel.dylib        	0x00000001d9eb5af8 mach_msg2_trap + 8
1   libsystem_kernel.dylib        	0x00000001d9eb5890 mach_msg2_internal + 80 (mach_msg.c:201)
2   libsystem_kernel.dylib        	0x00000001d9eb57a8 mach_msg_overwrite + 436 (mach_msg.c:0)
3   libsystem_kernel.dylib        	0x00000001d9eb55e8 mach_msg + 24 (mach_msg.c:323)
4   CoreFoundation                	0x000000019199001c __CFRunLoopServiceMachPort + 160 (CFRunLoop.c:2624)
5   CoreFoundation                	0x000000019198df04 __CFRunLoopRun + 1208 (CFRunLoop.c:3007)
6   CoreFoundation                	0x000000019198d968 CFRunLoopRunSpecific + 608 (CFRunLoop.c:3420)
7   CoreFoundation                	0x000000019198d6cc CFRunLoopRun + 64 (CFRunLoop.c:3446)
8   ANEServices                   	0x000000020346288c H11ANE::H11ANEServicesThreadStart(H11ANE::H11ANEServicesThreadParams*) + 148 (H11ANEServicesPrivate.mm:176)
9   libsystem_pthread.dylib       	0x00000001ed93da90 _pthread_start + 136 (pthread.c:927)
10  libsystem_pthread.dylib       	0x00000001ed93cfcc thread_start + 8

Thread 11:
0   libsystem_pthread.dylib       	0x00000001ed93cfb8 start_wqthread + 0

Thread 12:
0   libsystem_pthread.dylib       	0x00000001ed93cfb8 start_wqthread + 0

Thread 13:
0   libsystem_pthread.dylib       	0x00000001ed93cfb8 start_wqthread + 0

Thread 14:
0   libsystem_pthread.dylib       	0x00000001ed93cfb8 start_wqthread + 0

Thread 15:
0   libsystem_pthread.dylib       	0x00000001ed93cfb8 start_wqthread + 0

Thread 16:
0   libsystem_pthread.dylib       	0x00000001ed93cfb8 start_wqthread + 0

Thread 17:
0   libsystem_pthread.dylib       	0x00000001ed93cfb8 start_wqthread + 0

Thread 18:
0   libsystem_pthread.dylib       	0x00000001ed93cfb8 start_wqthread + 0

Thread 19:
0   libsystem_pthread.dylib       	0x00000001ed93cfb8 start_wqthread + 0

Thread 20:
0   libsystem_pthread.dylib       	0x00000001ed93cfb8 start_wqthread + 0

Thread 21:
0   libsystem_pthread.dylib       	0x00000001ed93cfb8 start_wqthread + 0

Thread 22:
0   libsystem_pthread.dylib       	0x00000001ed93cfb8 start_wqthread + 0

Thread 23:
0   libsystem_pthread.dylib       	0x00000001ed93cfb8 start_wqthread + 0

Thread 24:
0   libsystem_pthread.dylib       	0x00000001ed93cfb8 start_wqthread + 0

Thread 25 name:
Thread 25:
0   libsystem_kernel.dylib        	0x00000001d9eb5af8 mach_msg2_trap + 8
1   libsystem_kernel.dylib        	0x00000001d9eb5890 mach_msg2_internal + 80 (mach_msg.c:201)
2   libsystem_kernel.dylib        	0x00000001d9eb57a8 mach_msg_overwrite + 436 (mach_msg.c:0)
3   libsystem_kernel.dylib        	0x00000001d9eb55e8 mach_msg + 24 (mach_msg.c:323)
4   CoreFoundation                	0x000000019199001c __CFRunLoopServiceMachPort + 160 (CFRunLoop.c:2624)
5   CoreFoundation                	0x000000019198df04 __CFRunLoopRun + 1208 (CFRunLoop.c:3007)
6   CoreFoundation                	0x000000019198d968 CFRunLoopRunSpecific + 608 (CFRunLoop.c:3420)
7   Foundation                    	0x000000019081c4a8 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 212 (NSRunLoop.m:373)
8   Foundation                    	0x000000019081aff0 -[NSRunLoop(NSRunLoop) run] + 64 (NSRunLoop.m:398)
9   SwiftUI                       	0x0000000195e5edfc static DisplayLink.asyncThread(arg:) + 732 (_UIHostingView.swift:1173)
10  SwiftUI                       	0x0000000195e5eee0 @objc static DisplayLink.asyncThread(arg:) + 88 (:0)
11  Foundation                    	0x000000019088da9c __NSThread__start__ + 732 (NSThread.m:991)
12  libsystem_pthread.dylib       	0x00000001ed93da90 _pthread_start + 136 (pthread.c:927)
13  libsystem_pthread.dylib       	0x00000001ed93cfcc thread_start + 8


Thread 6 crashed with ARM Thread State (64-bit):
    x0: 0x000000010e4f3640   x1: 0x000000015bc78000   x2: 0x00000000000005e0   x3: 0x000000010e4f4000
    x4: 0x000000004d784000   x5: 0x0000000000000020   x6: 0x00000000000007e0   x7: 0x00000000000003a3
    x8: 0x000000010e15fec0   x9: 0x0000000000000fc0  x10: 0x000000000000cb05  x11: 0x00000001f2f02200
   x12: 0x0000010000000000  x13: 0x0000000000000000  x14: 0x0000000000000000  x15: 0x0000000000000000
   x16: 0x00000001ed886a60  x17: 0x00000001fe060a10  x18: 0x0000000000000000  x19: 0x0000000000000fc0
   x20: 0x000000016f9aa660  x21: 0x000000015bc77640  x22: 0x00000000000003a2  x23: 0x0000000000000fc0
   x24: 0x00000000000007e0  x25: 0x000000010e15fec0  x26: 0x000000030320a010  x27: 0x0000000300b08e70
   x28: 0x00000000000007e0   fp: 0x000000016f9aa610   lr: 0x00000001a2075760
    sp: 0x000000016f9aa5f0   pc: 0x00000001ed886b1c cpsr: 0x20001000
   esr: 0x92000007 (Data Abort) byte read Translation fault


Binary Images:
        0x100798000 -         0x1007f7fff EEEE arm64  <2ea84ee7733d388e80975eacff00e41b> /private/var/containers/Bundle/Application/4B3964E4-0144-46D7-A7C5-2C60EADD528E/EEEE.app/EEEE
        0x10097c000 -         0x100987fff libobjc-trampolines.dylib arm64e  <19bc6b58cbf535a583a5fc742451547d> /private/preboot/Cryptexes/OS/usr/lib/libobjc-trampolines.dylib
        0x1907f1000 -         0x19137cfff Foundation arm64e   /System/Library/Frameworks/Foundation.framework/Foundation
        0x19195a000 -         0x191e87fff CoreFoundation arm64e  <3a5f992ad1cd312ebd2ef7c66343a417> /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
        0x193bd6000 -         0x1956e6fff UIKitCore arm64e  <7bf01cfc23f1326aafd8ad967ffece28> /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore
        0x195794000 -         0x19751dfff SwiftUI arm64e  <052e38315d203d889666b92ebe26278d> /System/Library/Frameworks/SwiftUI.framework/SwiftUI
        0x19751e000 -         0x1979a2fdf ImageIO arm64e   /System/Library/Frameworks/ImageIO.framework/ImageIO
        0x199853000 -         0x199899fff libdispatch.dylib arm64e   /usr/lib/system/libdispatch.dylib
        0x19989a000 -         0x199917fff libsystem_c.dylib arm64e  <3b5201c515d0335fa91d0c63e1f6c6dc> /usr/lib/system/libsystem_c.dylib
        0x19e671000 -         0x19eb3afff CoreMotion arm64e  <1e51658a881b3bbb95c26c7c9701e878> /System/Library/Frameworks/CoreMotion.framework/CoreMotion
        0x1a1f65000 -         0x1a22e6fff CoreImage arm64e  <3d2ac24308803ba9bbf3a214454875e0> /System/Library/Frameworks/CoreImage.framework/CoreImage
        0x1b4ea9000 -         0x1b4f35be3 dyld arm64e  <7be2b7573b3d3e918cb774f3887660c7> /usr/lib/dyld
        0x1d5c80000 -         0x1d5c88fff GraphicsServices arm64e  <4cb7e98636bf38018f495d8c3c4a2127> /System/Library/PrivateFrameworks/GraphicsServices.framework/GraphicsServices
        0x1d9eb4000 -         0x1d9eedfef libsystem_kernel.dylib arm64e   /usr/lib/system/libsystem_kernel.dylib
        0x1ed886000 -         0x1ed88cfeb libsystem_platform.dylib arm64e   /usr/lib/system/libsystem_platform.dylib
        0x1ed93b000 -         0x1ed947fff libsystem_pthread.dylib arm64e   /usr/lib/system/libsystem_pthread.dylib
        0x203453000 -         0x203476fff ANEServices arm64e  <4e2bd607feab38268e097d730424a419> /System/Library/PrivateFrameworks/ANEServices.framework/ANEServices

EOF
</a>

I was able to reproduce the issue locally by using "Address Sanitizer" debug diagnostic setting in Xcode. Looks like the CVPixelBuffer may have some corruption in some cases. In any case, it is clear the issue is nothing to do with VideoToolbox.

Hello @MPDroid, can you provide a crash log? See Posting a Crash Report.

Accepted Answer

Since the original post, changed the approach to create the JPEG image - used CIContext instead of VideoToolbox

      let colorSpace = CGColorSpace(name: CGColorSpace.sRGB)
      let jpeg = ciContext.jpegRepresentation(of: CIImage(cvPixelBuffer: pixelBuffer), colorSpace: colorSpace!) 

It was still crashing. Attached is a crash log from using the CIContext approach.

Incident Identifier: 40F7E148-54D4-42B8-8159-C6B7607B59A7
Distributor ID:      com.apple.TestFlight
Hardware Model:      iPhone16,1
Process:             EEEE [1111]
Path:                /private/var/containers/Bundle/Application/4B3964E4-0144-46D7-A7C5-2C60EADD528E/EEEE.app/EEEE
Identifier:          com.www.EEEE
Version:             1.11 (13)
AppStoreTools:       15E204
AppVariant:          1:iPhone16,1:17.4
Beta:                YES
Code Type:           ARM-64 (Native)
Role:                Foreground
Parent Process:      launchd [1]
Coalition:           com.www.EEEE [1504]

Date/Time:           2024-04-30 20:06:22.6123 -0500
Launch Time:         2024-04-30 20:05:50.9456 -0500
OS Version:          iPhone OS 17.4.1 (21E236)
Release Type:        User
Baseband Version:    1.55.04
Report Version:      104

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x000000015bc78000
Exception Codes: 0x0000000000000001, 0x000000015bc78000
VM Region Info: 0x15bc78000 is not in any region.  Bytes after previous region: 1  Bytes before following region: 65536
      REGION TYPE                 START - END      [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      MALLOC_LARGE             15b1bc000-15bc78000 [ 10.7M] rw-/rwx SM=PRV  
--->  GAP OF 0x10000 BYTES
      MALLOC_LARGE             15bc88000-15bc98000 [   64K] rw-/rwx SM=PRV  
Termination Reason: SIGNAL 11 Segmentation fault: 11
Terminating Process: exc handler [6561]

Triggered by Thread:  6


Thread 0 name:
Thread 0:
0   libsystem_kernel.dylib        	0x00000001d9eb5af8 mach_msg2_trap + 8
1   libsystem_kernel.dylib        	0x00000001d9eb5890 mach_msg2_internal + 80 (mach_msg.c:201)
2   libsystem_kernel.dylib        	0x00000001d9eb57a8 mach_msg_overwrite + 436 (mach_msg.c:0)
3   libsystem_kernel.dylib        	0x00000001d9eb55e8 mach_msg + 24 (mach_msg.c:323)
4   CoreFoundation                	0x000000019199001c __CFRunLoopServiceMachPort + 160 (CFRunLoop.c:2624)
5   CoreFoundation                	0x000000019198df04 __CFRunLoopRun + 1208 (CFRunLoop.c:3007)
6   CoreFoundation                	0x000000019198d968 CFRunLoopRunSpecific + 608 (CFRunLoop.c:3420)
7   GraphicsServices              	0x00000001d5c834e0 GSEventRunModal + 164 (GSEvent.c:2196)
8   UIKitCore                     	0x0000000193e00edc -[UIApplication _run] + 888 (UIApplication.m:3692)
9   UIKitCore                     	0x0000000193e00518 UIApplicationMain + 340 (UIApplication.m:5282)
10  SwiftUI                       	0x00000001967c7860 closure #1 in KitRendererCommon(_:) + 168 (UIKitApp.swift:51)
11  SwiftUI                       	0x00000001967c76a8 runApp<a>(_:) + 152 (UIKitApp.swift:14)
12  SwiftUI                       	0x00000001963e39fc static App.main() + 132 (App.swift:114)
13  EEEE                          	0x00000001007bd260 static EEEEApp.$main() + 52 (EEEEApp.swift:0)
14  EEEE                          	0x00000001007bd260 main + 64
15  dyld                          	0x00000001b4eaed84 start + 2240 (dyldMain.cpp:1298)

Thread 1:
0   libsystem_pthread.dylib       	0x00000001ed93cfb8 start_wqthread + 0

Thread 2:
0   libsystem_pthread.dylib       	0x00000001ed93cfb8 start_wqthread + 0

Thread 3:
0   libsystem_pthread.dylib       	0x00000001ed93cfb8 start_wqthread + 0

Thread 4 name:
Thread 4:
0   libsystem_kernel.dylib        	0x00000001d9eb654c kevent_id + 8
1   libdispatch.dylib             	0x00000001998797d4 _dispatch_kq_poll + 228 (event_kevent.c:760)
2   libdispatch.dylib             	0x000000019987a1bc _dispatch_event_loop_wait_for_ownership + 436 (event_kevent.c:2232)
3   libdispatch.dylib             	0x0000000199866594 __DISPATCH_WAIT_FOR_QUEUE__ + 340 (queue.c:1700)
4   libdispatch.dylib             	0x000000019986615c _dispatch_sync_f_slow + 148 (queue.c:1784)
5   CoreImage                     	0x00000001a21b5f4c GetSurfaceFromCacheAndFill + 428 (surface-cache.cpp:1190)
6   CoreImage                     	0x00000001a21a1e44 CI::ProviderNode::surfaceForROI(CI::Context const*, CGRect const&) const + 992 (node-provider.cpp:453)
7   CoreImage                     	0x00000001a1f9b6ac CI::Context::bind_sampler(CI::TextureSampler const*, CI::roiKey const&, int, CI::KernelArgumentType, CI::TileTask*) + 1124 (context.cpp:795)
8   CoreImage                     	0x00000001a1f79fa0 CI::MetalContext::bind_arguments(CI::ProgramNode const*, CGRect const&, CGRect const&, CGSize const&, CI::TileTask*) + 1280 (context-metal.mm:2027)
9   CoreImage                     	0x00000001a1f796cc CI::MetalContext::render_node(CI::TileTask*, CI::ProgramNode*, CGRect const&, CGRect const&, void const**, __IOSurface**, unsigned long) + 1044 (context-metal.mm:1508)
10  CoreImage                     	0x00000001a1f97490 CI::MetalContext::render_root_node(CI::TileTask*, CI::ProgramNode*, CGRect const&, void () block_pointer, void () block_pointer) + 596 (context-metal.mm:1598)
11  CoreImage                     	0x00000001a1f7814c CI::Context::recursive_render(CI::TileTask*, CI::roiKey const&, CI::Node*, bool) + 2244 (context.cpp:514)
12  CoreImage                     	0x00000001a1f77870 CI::Context::render(CI::ProgramNode*, CGRect const&) + 176 (context.cpp:558)
13  CoreImage                     	0x00000001a1fa5144 invocation function for block in CI::image_render_to_surface(CI::Context*, CI::Image*, CGRect, __IOSurface*, CI::RenderDestination const*) + 72 (render.cpp:2784)
14  CoreImage                     	0x00000001a1f921a0 CI::recursive_tile(CI::RenderTask*, CI::Context*, CI::RenderDestination const*, char const*, CI::Node*, CGRect const&, CI::PixelFormat, CI::swizzle_info const&, CI::TileTask* (CI::ProgramNode*, CGR... + 4140 (render.cpp:2002)
15  CoreImage                     	0x00000001a1f90f8c CI::tile_node_graph(CI::Context*, CI::RenderDestination const*, char const*, CI::Node*, CGRect const&, CI::PixelFormat, CI::swizzle_info const&, CI::TileTask* (CI::ProgramNode*, CGRect) block_pointer) + 476 (render.cpp:2107)
16  CoreImage                     	0x00000001a1f90ac8 CI::image_render_to_surface(CI::Context*, CI::Image*, CGRect, __IOSurface*, CI::RenderDestination const*) + 2304 (render.cpp:2781)
17  CoreImage                     	0x00000001a1f8f40c -[CIContext(CIRenderDestination) _startTaskToRender:toDestination:forPrepareRender:forClear:error:] + 2076 (CIRenderDestination.mm:1966)
18  CoreImage                     	0x00000001a1f8ebd4 -[CIContext(CIRenderDestination) startTaskToRender:fromRect:toDestination:atPoint:error:] + 120 (CIRenderDestination.mm:1709)
19  CoreImage                     	0x00000001a1ff6560 invocation function for block in CI::copyIOSurfaceCallback(void*, CGImageProvider*, __CFDictionary const*) + 160 (CIContext_CGImage.mm:377)
20  libdispatch.dylib             	0x0000000199856dd4 _dispatch_client_callout + 20 (object.m:576)
21  libdispatch.dylib             	0x00000001998662c4 _dispatch_lane_barrier_sync_invoke_and_complete + 56 (queue.c:1100)
22  CoreImage                     	0x00000001a1ff6148 CI::copyIOSurfaceCallback(void*, CGImageProvider*, __CFDictionary const*) + 624 (CIContext_CGImage.mm:364)
23  ImageIO                       	0x0000000197683ad8 HEIFWritePlugin::writeImageAtIndex(IIOImagePixelDataProvider*, CGImage*, IIODictionary*, IIODictionary*, unsigned int) + 860 (HEIF_writePlugin.cpp:682)
24  ImageIO                       	0x0000000197686150 HEIFWritePlugin::writeAll() + 412 (HEIF_writePlugin.cpp:1526)
25  ImageIO                       	0x000000019766c5a0 IIO_Writer_HEIF::write(void*, void*) + 112 (HEIF_writer.cpp:130)
26  ImageIO                       	0x00000001976b9130 IIOImageDestination::finalizeDestination() + 896 (CGImageDestination.cpp:3559)
27  ImageIO                       	0x00000001976bb590 CGImageDestinationFinalize + 180 (CGImageDestination.cpp:4788)
28  CoreImage                     	0x00000001a1ff758c -[CIContext(ImageRepresentation) _dataRepresentationOfImage:UTIType:format:premultiplied:colorSpace:options:addAuxData:keysToMerge:error:] + 3828 (CIContext_ImageReps.mm:292)
29  CoreImage                     	0x00000001a1ff7e10 -[CIContext(ImageRepresentation) _JPEGRepresentationOfImage:colorSpace:options:error:] + 260 (CIContext_ImageReps.mm:662)
30  EEEE                          	0x00000001007aabe8 closure #1 in DataSet.addItem(name:pixelBuffer:source:save:ciContext:) + 472 (DataSetExtension.swift:124)
31  EEEE                          	0x00000001007b7b48 specialized autoreleasepool</a><a>(invoking:) + 56 (DataSetExtension.swift:109)
32  EEEE                          	0x00000001007b7b48 DataSet.addItem(name:pixelBuffer:source:save:ciContext:) + 56 (CameraProcessor.swift:0)
33  EEEE                          	0x00000001007b7b48 closure #1 in closure #5 in CameraProcessor.processCoreML(videoPixelBuffer:depthInfo:) + 420
34  EEEE                          	0x00000001007bc038 partial apply for closure #1 in closure #5 in CameraProcessor.processCoreML(videoPixelBuffer:depthInfo:) + 28 (:0)
35  EEEE                          	0x00000001007b9570 closure #1 in static ObjC.catchException(_:) + 36 (CameraProcessor.swift:417)
36  EEEE                          	0x00000001007bc07c thunk for @callee_guaranteed (@unowned AutoreleasingUnsafeMutablePointer?) -> () + 4 (:0)
37  EEEE                          	0x00000001007bc07c partial apply for thunk for @callee_guaranteed (@unowned AutoreleasingUnsafeMutablePointer?) -> () + 20
38  EEEE                          	0x00000001007b95d0 thunk for @escaping @callee_guaranteed (@unowned AutoreleasingUnsafeMutablePointer?) -> () + 24 (:0)
39  EEEE                          	0x00000001007a0044 +[ObjC catchException:error:] + 68 (ObjC.m:15)
40  EEEE                          	0x00000001007b84b8 static ObjC.catchException(_:) + 244 (CameraProcessor.swift:415)
41  EEEE                          	0x00000001007b77cc closure #5 in CameraProcessor.processCoreML(videoPixelBuffer:depthInfo:) + 292 (CameraProcessor.swift:190)
42  EEEE                          	0x00000001007dca34 thunk for @escaping @callee_guaranteed @Sendable () -> () + 28 (:0)
43  libdispatch.dylib             	0x000000019985513c _dispatch_call_block_and_release + 32 (init.c:1530)
44  libdispatch.dylib             	0x0000000199856dd4 _dispatch_client_callout + 20 (object.m:576)
45  libdispatch.dylib             	0x0000000199868a6c _dispatch_root_queue_drain + 864 (queue.c:7136)
46  libdispatch.dylib             	0x000000019986909c _dispatch_worker_thread2 + 156 (queue.c:7204)
47  libsystem_pthread.dylib       	0x00000001ed93cee4 _pthread_wqthread + 228 (pthread.c:2678)
48  libsystem_pthread.dylib       	0x00000001ed93cfc0 start_wqthread + 8

Thread 5:
0   libsystem_pthread.dylib       	0x00000001ed93cfb8 start_wqthread + 0

Thread 6 name:
Thread 6 Crashed:
0   libsystem_platform.dylib      	0x00000001ed886b1c _platform_memmove + 188
1   CoreImage                     	0x00000001a2075760 __42-[CIImage _initWithCVImageBuffer:options:]_block_invoke_2 + 72 (CIImage.mm:2683)
2   CoreImage                     	0x00000001a212fc34 PixelBufferApplyOnePlaneReadOnlyBlock + 312 (PixelBufferUtils.c:0)
3   CoreImage                     	0x00000001a20756f8 __42-[CIImage _initWithCVImageBuffer:options:]_block_invoke + 212 (CIImage.mm:2675)
4   CoreImage                     	0x00000001a21a2578 invocation function for block in CI::ProviderNode::surfaceForROI(CI::Context const*, CGRect const&) const + 248 (node-provider.cpp:390)
5   CoreImage                     	0x00000001a1f8cfd0 SurfaceApplyPlaneBlock + 404 (Surface.c:217)
6   CoreImage                     	0x00000001a21a2474 invocation function for block in CI::ProviderNode::surfaceForROI(CI::Context const*, CGRect const&) const + 120 (node-provider.cpp:364)
7   CoreImage                     	0x00000001a21b5a1c invocation function for block in CI::SurfaceCacheEntry::fillAsync() + 128 (surface-cache.cpp:359)
8   libdispatch.dylib             	0x000000019985513c _dispatch_call_block_and_release + 32 (init.c:1530)
9   libdispatch.dylib             	0x0000000199856dd4 _dispatch_client_callout + 20 (object.m:576)
10  libdispatch.dylib             	0x000000019985e400 _dispatch_lane_serial_drain + 748 (queue.c:3900)
11  libdispatch.dylib             	0x000000019985ef64 _dispatch_lane_invoke + 432 (queue.c:3991)
12  libdispatch.dylib             	0x0000000199869cb4 _dispatch_root_queue_drain_deferred_wlh + 288 (queue.c:6998)
13  libdispatch.dylib             	0x0000000199869528 _dispatch_workloop_worker_thread + 404 (queue.c:6592)
14  libsystem_pthread.dylib       	0x00000001ed93cf20 _pthread_wqthread + 288 (pthread.c:2665)
15  libsystem_pthread.dylib       	0x00000001ed93cfc0 start_wqthread + 8

Thread 7 name:
Thread 7:
0   libsystem_kernel.dylib        	0x00000001d9eb5af8 mach_msg2_trap + 8
1   libsystem_kernel.dylib        	0x00000001d9eb5890 mach_msg2_internal + 80 (mach_msg.c:201)
2   libsystem_kernel.dylib        	0x00000001d9eb57a8 mach_msg_overwrite + 436 (mach_msg.c:0)
3   libsystem_kernel.dylib        	0x00000001d9eb55e8 mach_msg + 24 (mach_msg.c:323)
4   CoreFoundation                	0x000000019199001c __CFRunLoopServiceMachPort + 160 (CFRunLoop.c:2624)
5   CoreFoundation                	0x000000019198df04 __CFRunLoopRun + 1208 (CFRunLoop.c:3007)
6   CoreFoundation                	0x000000019198d968 CFRunLoopRunSpecific + 608 (CFRunLoop.c:3420)
7   Foundation                    	0x000000019081c4a8 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 212 (NSRunLoop.m:373)
8   Foundation                    	0x00000001908464e8 -[NSRunLoop(NSRunLoop) runUntilDate:] + 64 (NSRunLoop.m:420)
9   UIKitCore                     	0x0000000193d63ac8 -[UIEventFetcher threadMain] + 420 (UIEventFetcher.m:1201)
10  Foundation                    	0x000000019088da9c __NSThread__start__ + 732 (NSThread.m:991)
11  libsystem_pthread.dylib       	0x00000001ed93da90 _pthread_start + 136 (pthread.c:927)
12  libsystem_pthread.dylib       	0x00000001ed93cfcc thread_start + 8

Thread 8:
0   libsystem_pthread.dylib       	0x00000001ed93cfb8 start_wqthread + 0

Thread 9 name:
Thread 9:
0   libsystem_kernel.dylib        	0x00000001d9eb5af8 mach_msg2_trap + 8
1   libsystem_kernel.dylib        	0x00000001d9eb5890 mach_msg2_internal + 80 (mach_msg.c:201)
2   libsystem_kernel.dylib        	0x00000001d9eb57a8 mach_msg_overwrite + 436 (mach_msg.c:0)
3   libsystem_kernel.dylib        	0x00000001d9eb55e8 mach_msg + 24 (mach_msg.c:323)
4   CoreFoundation                	0x000000019199001c __CFRunLoopServiceMachPort + 160 (CFRunLoop.c:2624)
5   CoreFoundation                	0x000000019198df04 __CFRunLoopRun + 1208 (CFRunLoop.c:3007)
6   CoreFoundation                	0x000000019198d968 CFRunLoopRunSpecific + 608 (CFRunLoop.c:3420)
7   CoreFoundation                	0x000000019198d6cc CFRunLoopRun + 64 (CFRunLoop.c:3446)
8   CoreMotion                    	0x000000019e95a3c0 CLMotionCore::runMotionThread(void*) + 1292 (CLMotionCore.mm:376)
9   libsystem_pthread.dylib       	0x00000001ed93da90 _pthread_start + 136 (pthread.c:927)
10  libsystem_pthread.dylib       	0x00000001ed93cfcc thread_start + 8

Thread 10 name:
Thread 10:
0   libsystem_kernel.dylib        	0x00000001d9eb5af8 mach_msg2_trap + 8
1   libsystem_kernel.dylib        	0x00000001d9eb5890 mach_msg2_internal + 80 (mach_msg.c:201)
2   libsystem_kernel.dylib        	0x00000001d9eb57a8 mach_msg_overwrite + 436 (mach_msg.c:0)
3   libsystem_kernel.dylib        	0x00000001d9eb55e8 mach_msg + 24 (mach_msg.c:323)
4   CoreFoundation                	0x000000019199001c __CFRunLoopServiceMachPort + 160 (CFRunLoop.c:2624)
5   CoreFoundation                	0x000000019198df04 __CFRunLoopRun + 1208 (CFRunLoop.c:3007)
6   CoreFoundation                	0x000000019198d968 CFRunLoopRunSpecific + 608 (CFRunLoop.c:3420)
7   CoreFoundation                	0x000000019198d6cc CFRunLoopRun + 64 (CFRunLoop.c:3446)
8   ANEServices                   	0x000000020346288c H11ANE::H11ANEServicesThreadStart(H11ANE::H11ANEServicesThreadParams*) + 148 (H11ANEServicesPrivate.mm:176)
9   libsystem_pthread.dylib       	0x00000001ed93da90 _pthread_start + 136 (pthread.c:927)
10  libsystem_pthread.dylib       	0x00000001ed93cfcc thread_start + 8

Thread 11:
0   libsystem_pthread.dylib       	0x00000001ed93cfb8 start_wqthread + 0

Thread 12:
0   libsystem_pthread.dylib       	0x00000001ed93cfb8 start_wqthread + 0

Thread 13:
0   libsystem_pthread.dylib       	0x00000001ed93cfb8 start_wqthread + 0

Thread 14:
0   libsystem_pthread.dylib       	0x00000001ed93cfb8 start_wqthread + 0

Thread 15:
0   libsystem_pthread.dylib       	0x00000001ed93cfb8 start_wqthread + 0

Thread 16:
0   libsystem_pthread.dylib       	0x00000001ed93cfb8 start_wqthread + 0

Thread 17:
0   libsystem_pthread.dylib       	0x00000001ed93cfb8 start_wqthread + 0

Thread 18:
0   libsystem_pthread.dylib       	0x00000001ed93cfb8 start_wqthread + 0

Thread 19:
0   libsystem_pthread.dylib       	0x00000001ed93cfb8 start_wqthread + 0

Thread 20:
0   libsystem_pthread.dylib       	0x00000001ed93cfb8 start_wqthread + 0

Thread 21:
0   libsystem_pthread.dylib       	0x00000001ed93cfb8 start_wqthread + 0

Thread 22:
0   libsystem_pthread.dylib       	0x00000001ed93cfb8 start_wqthread + 0

Thread 23:
0   libsystem_pthread.dylib       	0x00000001ed93cfb8 start_wqthread + 0

Thread 24:
0   libsystem_pthread.dylib       	0x00000001ed93cfb8 start_wqthread + 0

Thread 25 name:
Thread 25:
0   libsystem_kernel.dylib        	0x00000001d9eb5af8 mach_msg2_trap + 8
1   libsystem_kernel.dylib        	0x00000001d9eb5890 mach_msg2_internal + 80 (mach_msg.c:201)
2   libsystem_kernel.dylib        	0x00000001d9eb57a8 mach_msg_overwrite + 436 (mach_msg.c:0)
3   libsystem_kernel.dylib        	0x00000001d9eb55e8 mach_msg + 24 (mach_msg.c:323)
4   CoreFoundation                	0x000000019199001c __CFRunLoopServiceMachPort + 160 (CFRunLoop.c:2624)
5   CoreFoundation                	0x000000019198df04 __CFRunLoopRun + 1208 (CFRunLoop.c:3007)
6   CoreFoundation                	0x000000019198d968 CFRunLoopRunSpecific + 608 (CFRunLoop.c:3420)
7   Foundation                    	0x000000019081c4a8 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 212 (NSRunLoop.m:373)
8   Foundation                    	0x000000019081aff0 -[NSRunLoop(NSRunLoop) run] + 64 (NSRunLoop.m:398)
9   SwiftUI                       	0x0000000195e5edfc static DisplayLink.asyncThread(arg:) + 732 (_UIHostingView.swift:1173)
10  SwiftUI                       	0x0000000195e5eee0 @objc static DisplayLink.asyncThread(arg:) + 88 (:0)
11  Foundation                    	0x000000019088da9c __NSThread__start__ + 732 (NSThread.m:991)
12  libsystem_pthread.dylib       	0x00000001ed93da90 _pthread_start + 136 (pthread.c:927)
13  libsystem_pthread.dylib       	0x00000001ed93cfcc thread_start + 8


Thread 6 crashed with ARM Thread State (64-bit):
    x0: 0x000000010e4f3640   x1: 0x000000015bc78000   x2: 0x00000000000005e0   x3: 0x000000010e4f4000
    x4: 0x000000004d784000   x5: 0x0000000000000020   x6: 0x00000000000007e0   x7: 0x00000000000003a3
    x8: 0x000000010e15fec0   x9: 0x0000000000000fc0  x10: 0x000000000000cb05  x11: 0x00000001f2f02200
   x12: 0x0000010000000000  x13: 0x0000000000000000  x14: 0x0000000000000000  x15: 0x0000000000000000
   x16: 0x00000001ed886a60  x17: 0x00000001fe060a10  x18: 0x0000000000000000  x19: 0x0000000000000fc0
   x20: 0x000000016f9aa660  x21: 0x000000015bc77640  x22: 0x00000000000003a2  x23: 0x0000000000000fc0
   x24: 0x00000000000007e0  x25: 0x000000010e15fec0  x26: 0x000000030320a010  x27: 0x0000000300b08e70
   x28: 0x00000000000007e0   fp: 0x000000016f9aa610   lr: 0x00000001a2075760
    sp: 0x000000016f9aa5f0   pc: 0x00000001ed886b1c cpsr: 0x20001000
   esr: 0x92000007 (Data Abort) byte read Translation fault


Binary Images:
        0x100798000 -         0x1007f7fff EEEE arm64  <2ea84ee7733d388e80975eacff00e41b> /private/var/containers/Bundle/Application/4B3964E4-0144-46D7-A7C5-2C60EADD528E/EEEE.app/EEEE
        0x10097c000 -         0x100987fff libobjc-trampolines.dylib arm64e  <19bc6b58cbf535a583a5fc742451547d> /private/preboot/Cryptexes/OS/usr/lib/libobjc-trampolines.dylib
        0x1907f1000 -         0x19137cfff Foundation arm64e   /System/Library/Frameworks/Foundation.framework/Foundation
        0x19195a000 -         0x191e87fff CoreFoundation arm64e  <3a5f992ad1cd312ebd2ef7c66343a417> /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
        0x193bd6000 -         0x1956e6fff UIKitCore arm64e  <7bf01cfc23f1326aafd8ad967ffece28> /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore
        0x195794000 -         0x19751dfff SwiftUI arm64e  <052e38315d203d889666b92ebe26278d> /System/Library/Frameworks/SwiftUI.framework/SwiftUI
        0x19751e000 -         0x1979a2fdf ImageIO arm64e   /System/Library/Frameworks/ImageIO.framework/ImageIO
        0x199853000 -         0x199899fff libdispatch.dylib arm64e   /usr/lib/system/libdispatch.dylib
        0x19989a000 -         0x199917fff libsystem_c.dylib arm64e  <3b5201c515d0335fa91d0c63e1f6c6dc> /usr/lib/system/libsystem_c.dylib
        0x19e671000 -         0x19eb3afff CoreMotion arm64e  <1e51658a881b3bbb95c26c7c9701e878> /System/Library/Frameworks/CoreMotion.framework/CoreMotion
        0x1a1f65000 -         0x1a22e6fff CoreImage arm64e  <3d2ac24308803ba9bbf3a214454875e0> /System/Library/Frameworks/CoreImage.framework/CoreImage
        0x1b4ea9000 -         0x1b4f35be3 dyld arm64e  <7be2b7573b3d3e918cb774f3887660c7> /usr/lib/dyld
        0x1d5c80000 -         0x1d5c88fff GraphicsServices arm64e  <4cb7e98636bf38018f495d8c3c4a2127> /System/Library/PrivateFrameworks/GraphicsServices.framework/GraphicsServices
        0x1d9eb4000 -         0x1d9eedfef libsystem_kernel.dylib arm64e   /usr/lib/system/libsystem_kernel.dylib
        0x1ed886000 -         0x1ed88cfeb libsystem_platform.dylib arm64e   /usr/lib/system/libsystem_platform.dylib
        0x1ed93b000 -         0x1ed947fff libsystem_pthread.dylib arm64e   /usr/lib/system/libsystem_pthread.dylib
        0x203453000 -         0x203476fff ANEServices arm64e  <4e2bd607feab38268e097d730424a419> /System/Library/PrivateFrameworks/ANEServices.framework/ANEServices

EOF
</a>

I was able to reproduce the issue locally by using "Address Sanitizer" debug diagnostic setting in Xcode. Looks like the CVPixelBuffer may have some corruption in some cases. In any case, it is clear the issue is nothing to do with VideoToolbox.

iOS App crashes while converting CVPixelbuffer to JPG
 
 
Q