title: Crash: Engine Marked As Needing Optimization
body: <p>I have an app out in the field that started crashing sometime in iOS 11 with the following message:</p>
  
  <blockquote>
    <p>CRASH: Engine marked as needing optimization even though it's already in progress.</p>
  </blockquote>
  
  <p>The crash is somewhere in <code>UIKit -&gt; Foundation -&gt; CoreFoundation -&gt; libocj.A.dylib -&gt; CoreFoundation</code>, but the crash logs I get are redacted, so I don't know much more than that. I normally symbolicate them, but the symbolication only works for my app, not for library code, so I'll need to get a device from the field shipped here to get the full crash log from the device.</p>
  
  <p>Until then, does anyone have any clues to what would cause this kind of crash, or any good starting points to begin investigation?</p>
  
  <pre><code>0 CoreFoundation exceptionPreprocess (in CoreFoundation) + 148
  1 libobjc.A.dylib objc_exception_throw + 56
  2 CoreFoundation +[NSException raise:format:] (in CoreFoundation) + 0
  3 Foundation -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] (in Foundation) + 112
  4 Foundation -[NSISEngine _optimizeIfNotDisabled] (in Foundation) + 320
  5 Foundation -[NSISEngine tryToAddConstraintWithMarker:expression:integralizationAdjustment:mutuallyExclusiveConstraints:] (in Foundation) + 664
  6 Foundation -[NSLayoutConstraint _addLoweredExpression:toEngine:integralizationAdjustment:lastLoweredConstantWasRounded:mutuallyExclusiveConstraints:] (in Foundation) + 284
  7 Foundation -[NSLayoutConstraint _addToEngine:integralizationAdjustment:mutuallyExclusiveConstraints:] (in Foundation) + 272
  8 UIKit -[UIView(UIConstraintBasedLayout) _layoutEngine_didAddLayoutConstraint:roundingAdjustment:mutuallyExclusiveConstraints:] (in UIKit) + 488
  9 UIKit -[UIView(UIConstraintBasedLayout) _tryToAddConstraintWithoutUpdatingConstraintsArray:roundingAdjustment:mutuallyExclusiveConstraints:] (in UIKit) + 36
  10 UIKit -[UIView(UIConstraintBasedLayout) _updateContentSizeConstraints] (in UIKit) + 696
  11 UIKit -[UIView(AdditionalLayoutSupport) _updateSystemConstraints] (in UIKit) + 112
  12 UIKit -[UIView(AdditionalLayoutSupport) _sendUpdateConstraintsIfNecessaryForSecondPass:] (in UIKit) + 188
  13 UIKit -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededCollectingViews:forSecondPass:] (in UIKit) + 1008
  14 UIKit -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededCollectingViews:forSecondPass:] (in UIKit) + 712
  15 UIKit -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededCollectingViews:forSecondPass:] (in UIKit) + 712
  16 UIKit -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededCollectingViews:forSecondPass:] (in UIKit) + 712
  17 Foundation -[NSISEngine withBehaviors:performModifications:] (in Foundation) + 168
  18 UIKit 100-[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededWithViewForVariableChangeNotifications:]_block_invoke (in UIKit) + 92
  19 UIKit -[UIView(AdditionalLayoutSupport) _withUnsatisfiableConstraintsLoggingSuspendedIfEngineDelegateExists:] (in UIKit) + 116
  20 UIKit -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededWithViewForVariableChangeNotifications:] (in UIKit) + 168
  21 UIKit -[UIWindow(UIConstraintBasedLayout) _updateConstraintsIfNeededWithViewForVariableChangeNotifications:] (in UIKit) + 104
  22 UIKit -[UIView(AdditionalLayoutSupport) _updateConstraintsAtEngineLevelIfNeededWithViewForVariableChangeNotifications:] (in UIKit) + 428
  23 UIKit -[UIView(Hierarchy) _updateConstraintsAsNecessaryAndApplyLayoutFromEngine] (in UIKit) + 180
  24 UIKit -[UIView(CALayerDelegate) layoutSublayersOfLayer:] (in UIKit) + 1276
  25 QuartzCore -[CALayer layoutSublayers] (in QuartzCore) + 184
  26 QuartzCore CA::Layer::layout_if_needed(CA::Transaction*) (in QuartzCore) + 332
  27 QuartzCore CA::Context::commit_transaction(CA::Transaction*) (in QuartzCore) + 336
  28 QuartzCore CA::Transaction::commit() (in QuartzCore) + 540
  29 QuartzCore CA::Transaction::observer_callback(CFRunLoopObserver*, unsigned long, void*) (in QuartzCore) + 92
  30 CoreFoundation CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ (in CoreFoundation) + 32
  31 CoreFoundation CFRunLoopDoObservers (in CoreFoundation) + 412
  32 CoreFoundation CFRunLoopRun (in CoreFoundation) + 1292
  33 CoreFoundation CFRunLoopRunSpecific + 436
  34 GraphicsServices GSEventRunModal + 100
  35 UIKit UIApplicationMain + 208
  36 ios-app main (main.m:27)
  37 libdyld.dylib start (in libdyld.dylib) + 4
  </code></pre>