Assertion failed in img_colormask_stage in iOS 12 beta 2

My app crashes on the Xcode 10.0 beta 2 iOS 12 simulator with the console message

Assertion failed: (0), function img_colormask_stage, file /BuildRoot/Library/Caches/com.apple.xbs/Sources/CoreGraphics_Sim/CoreGraphics-1225/CoreGraphics/Images/CGSImage.c, line 3273.


The app works perfectly in other iOS versions in that same beta version of Xcode, and in Xcode 9.4.1, and has been a stable app on the App Store for many years. Does anybody have (and possibly resolved) similar issues with iOS 12 beta?


  1. Where do I find this source file CGSImage.c? I have looked in various hidden libraries, but could not find that path. I assume /BuildRoot is a relative or symbolic path and has to be prepended or replaced by something, but what?
  2. What assertion does CGSImage.c make at line 3273? This might at least give me a clue what is going wrong.
  3. Is this related to the known issue "Various CoreGraphics calls have been hardened against continuing with invalid parameters. In iOS 12 beta, these calls may now return NULL or return early. (38344690)" mentioned in the iOS 12 beta 2 Release Notes? Can anybody be more specific about what img_colormask_stage might have been hardened against? Will that issue ever be resolved, or at least replaced by some more specific warning?
  4. Is there a way to avoid this assertion? Clearly whatever happens did not disturb former iOS releases.


Here is the full stack trace. It does not refer to any code in my app and just appears in UIApplicationMain:

* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT

frame #0: 0x0000000111459b6e libsystem_kernel.dylib`__pthread_kill + 10

frame #1: 0x0000000111493080 libsystem_pthread.dylib`pthread_kill + 333

frame #2: 0x0000000111207b81 libsystem_c.dylib`abort + 127

frame #3: 0x00000001111d0222 libsystem_c.dylib`__assert_rtn + 320

frame #4: 0x000000010dc267eb CoreGraphics`img_colormask_stage + 35

frame #5: 0x000000010dc2b97d CoreGraphics`img_data_lock + 10045

frame #6: 0x000000010dc278eb CoreGraphics`CGSImageDataLock + 1234

frame #7: 0x000000010d9c3e49 CoreGraphics`ripc_AcquireRIPImageData + 401

frame #8: 0x000000010da4023b CoreGraphics`ripc_GetClipState + 2539

frame #9: 0x000000010dc45745 CoreGraphics`ripc_GetRenderingState + 147

frame #10: 0x000000010dce0dac CoreGraphics`draw_glyph_bitmaps + 65

frame #11: 0x000000010dce0361 CoreGraphics`ripc_DrawGlyphs + 1601

frame #12: 0x000000010db7fcfb CoreGraphics`CGContextDelegateDrawGlyphs + 468

frame #13: 0x000000010dbd371a CoreGraphics`dle_ExecuteDisplayList + 5485

frame #14: 0x000000010dbcbb50 CoreGraphics`dle_Execute + 331

frame #15: 0x000000010dbcb9d3 CoreGraphics`CGDisplayListDrawInContextDelegate + 716

frame #16: 0x000000011727f979 QuartzCore`CABackingStoreUpdate_ + 534

frame #17: 0x00000001173892ae QuartzCore`___ZN2CA5Layer8display_Ev_block_invoke + 44

frame #18: 0x0000000117381e43 QuartzCore`-[CALayer _display] + 2124

frame #19: 0x0000000117302b5e QuartzCore`CA::Context::commit_transaction(CA::Transaction*) + 646

frame #20: 0x0000000117337cc4 QuartzCore`CA::Transaction::commit() + 576

frame #21: 0x00000001153a9672 UIKitCore`_afterCACommitHandler + 280

frame #22: 0x000000010ec8aea7 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23

frame #23: 0x000000010ec852de CoreFoundation`__CFRunLoopDoObservers + 430

frame #24: 0x000000010ec85981 CoreFoundation`__CFRunLoopRun + 1553

frame #25: 0x000000010ec85031 CoreFoundation`CFRunLoopRunSpecific + 625

frame #26: 0x000000010f5f6136 GraphicsServices`GSEventRunModal + 62

frame #27: 0x000000011537f839 UIKitCore`UIApplicationMain + 140

* frame #28: 0x000000010c096bb0 Dog`main(argc=1, argv=0x00007ffee3b690f0) at main.m:15

frame #29: 0x0000000111125a61 libdyld.dylib`start + 1

Replies

Hi, my app get the same problem in iPhone device(version: ios12 beta 3), do you resolve it?

Thanks, your observation confirms that it is not just a simulator issue but occurs on real devices, too. I have not dared to install iOS 12 beta on my devices, partly because of this untraceable issue. No, I could not resolve the issue. Simulators on Xcode Version 10.0 beta 3 also still have the problem.

Hi, I have solved the problem.

Please check your code, maybe you're using CGContextDrawImage method with maskingColors. This method causes the crash of my app, you could try debugging it.

Have a good luck!

Can you elaborate how CGContextDrawImage crashed your app, and how you worked around it?


I don't use CGContextDrawImage in my code, but plenty of other functions working with CGContext. With your information I could narrow the issue down to two lines calling NSString:drawInRect:withAttributes: (which draws into a CGContext) and CGContextStrokeRect. The crash disappears when I comment these two lines out. However, I don't know what these functions might do wrong, and I need them for the correct appearance of the graphics in the app.