# Catching an assertion in CGImage

**URL:** <https://forum.xojo.com/t/catching-an-assertion-in-cgimage/65261>\
**Category:** macOS\
**Created:** [August 28, 2021, 2:02pm UTC](https://forum.xojo.com/t/catching-an-assertion-in-cgimage/65261 "2021-08-28T14:02:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike\_D](https://forum.xojo.com/user_avatar/forum.xojo.com/mike_d/32/266_2.png) [@Mike\_D](https://forum.xojo.com/u/Mike_D)\
**Post date:** [August 28, 2021, 2:02pm UTC](https://forum.xojo.com/t/catching-an-assertion-in-cgimage/65261/1 "2021-08-28T14:02:05Z")

</div>

I’m finding that certain (possibly corrupt) TIFF images will crash my app, with the following stack trace:

```auto
Application Specific Information:
Assertion failed: (0), function img_data_depth, file /System/Volumes/Data/SWE/macOS/BuildRoots/d7e177bcf5/Library/Caches/com.apple.xbs/Sources/CoreGraphics/CoreGraphics-1463.16.1/CoreGraphics/Images/CGSImage.c, line 4539.
 
Thread 4 Crashed:
0 libsystem_kernel.dylib 0x00007fff2049592e __pthread_kill + 10
1 libsystem_pthread.dylib 0x00007fff204c45bd pthread_kill + 263
2 libsystem_c.dylib 0x00007fff20419406 abort + 125
3 libsystem_c.dylib 0x00007fff204187d8 __assert_rtn + 314
4 com.apple.CoreGraphics 0x00007fff25518179 img_data_depth.cold.2 + 54
5 com.apple.CoreGraphics 0x00007fff2536493c img_data_depth + 1211
6 com.apple.CoreGraphics 0x00007fff25106a0b img_data_lock + 6275
7 com.apple.CoreGraphics 0x00007fff251016d0 CGSImageDataLock + 1230
8 com.apple.CoreGraphics 0x00007fff2510099f ripc_AcquireRIPImageData + 459
9 com.apple.CoreGraphics 0x00007fff250ff681 ripc_DrawImage + 1180
10 com.apple.CoreGraphics 0x00007fff250fe8d7 CGContextDrawImageWithOptions + 454
11 com.apple.AppKit 0x00007fff22f31045 __74-[NSImageRep drawInRect:fromRect:operation:fraction:respectFlipped:hints:]_block_invoke + 902
12 com.apple.AppKit 0x00007fff22f30b7a -[NSImageRep drawInRect:fromRect:operation:fraction:respectFlipped:hints:] + 936
13 XojoFramework.dylib 0x000000011038ad1d DrawableCocoaBitmap::CreateMaskFromAlpha() + 349
14 XojoFramework.dylib 0x0000000110464f35 Drawable::CopyMask() + 45
15 XojoFramework.dylib 0x00000001104cc63a PictureCopyMask + 236

```

Is there any way to trap this kind of error so it doesn’t terminate the app?

---

<div class="post-metadata">

**Author:** ![Christian\_Schmitz](https://forum.xojo.com/user_avatar/forum.xojo.com/christian_schmitz/32/158_2.png) [@Christian\_Schmitz](https://forum.xojo.com/u/Christian_Schmitz)\
**Post date:** [August 28, 2021, 3:11pm UTC](https://forum.xojo.com/t/catching-an-assertion-in-cgimage/65261/2 "2021-08-28T15:11:51Z")

</div>

You could load the tiff e.g. with [MBS Xojo Plugins](https://www.monkeybreadsoftware.de/xojo/) instead. That would not involve CGImage to load it.
