MBProgressHUD
MBProgressHUD copied to clipboard
Getting crashes with the constraints used in MBProgressHUD
We are receiving too many crashes from the users in Fabric with constraints used in MBProgressHUD. Here is the stacktrace received in Fabric:
Fatal Exception: NSInvalidArgumentException 0 CoreFoundation 0x185311d04 __exceptionPreprocess 1 libobjc.A.dylib 0x184560528 objc_exception_throw 2 Foundation 0x185e22ec8 +[NSIBPrototypingLayoutConstraint classFallbacksForKeyedArchiver] 3 Foundation 0x185c4bc54 -[NSLayoutConstraintParser finishConstraint] 4 Foundation 0x185c4aa20 -[NSLayoutConstraintParser parse] 5 Foundation 0x185c4a5c4 +[NSLayoutConstraintParser constraintsWithVisualFormat:options:metrics:views:] 6 MyApp 0x100672c64 __34-[MBProgressHUD updateConstraints]_block_invoke (MBProgressHUD.m:658) 7 CoreFoundation 0x1851eb988 -[__NSArrayM enumerateObjectsWithOptions:usingBlock:] 8 MyApp 0x100672a48 -[MBProgressHUD updateConstraints] (MBProgressHUD.m:675) 9 UIKit 0x18f246bb0 -[UIView(AdditionalLayoutSupport) _sendUpdateConstraintsIfNecessaryForSecondPass:] 10 UIKit 0x18f247078 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededCollectingViews:forSecondPass:] 11 UIKit 0x18f246f50 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededCollectingViews:forSecondPass:] 12 Foundation 0x185c4359c -[NSISEngine withBehaviors:performModifications:] 13 UIKit 0x18f247810 __100-[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededWithViewForVariableChangeNotifications:]_block_invoke 14 UIKit 0x18f2463fc -[UIView(AdditionalLayoutSupport) _withUnsatisfiableConstraintsLoggingSuspendedIfEngineDelegateExists:] 15 UIKit 0x18f24742c -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededWithViewForVariableChangeNotifications:] 16 UIKit 0x18f23e770 -[UIWindow(UIConstraintBasedLayout) _updateConstraintsIfNeededWithViewForVariableChangeNotifications:] 17 UIKit 0x18f248458 -[UIView(AdditionalLayoutSupport) _updateConstraintsAtEngineLevelIfNeededWithViewForVariableChangeNotifications:] 18 UIKit 0x18ea28f5c -[UIView(Hierarchy) _updateConstraintsAsNecessaryAndApplyLayoutFromEngine] 19 UIKit 0x18e746304 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] 20 QuartzCore 0x1892ffec8 -[CALayer layoutSublayers] 21 QuartzCore 0x189303fa8 CA::Layer::layout_if_needed(CA::Transaction*) 22 QuartzCore 0x189272a98 CA::Context::commit_transaction(CA::Transaction*) 23 QuartzCore 0x189298eb4 CA::Transaction::commit() 24 QuartzCore 0x189299cf4 CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) 25 CoreFoundation 0x1852b9848 CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION 26 CoreFoundation 0x1852b7200 __CFRunLoopDoObservers 27 CoreFoundation 0x1852b77bc __CFRunLoopRun 28 CoreFoundation 0x1851d7fb8 CFRunLoopRunSpecific 29 GraphicsServices 0x18706ff84 GSEventRunModal 30 UIKit 0x18e7ac2f4 UIApplicationMain 31 MyApp 0x1004b3404 main (main.m:14) 32 libdyld.dylib 0x184cfa56c start
Can anyone suggest a fix for the above?
The exception message would also be important here, not just the stack trace.
MBProgressHUD.m line 658 __34-[MBProgressHUD updateConstraints]_block_invoke
Fatal Exception: NSInvalidArgumentException Unable to parse constraint format: Unable to interpret '|' character, because the related view doesn't have a superview |-(>=margin)-[view]-(>=margin)-| ^
Looks like the constraints get updated either before the HUD is added to the view hierarchy, or after it is removed. Perhaps a simple if (self.superView) { return; }
at the top of -[MBProgressHUD updateConstraints]
would do the trick.
Do you have a way to reproduce this issue?
No, it is showing progress HUD normally at my end but I have been receiving the crash reports on the same via Fabric. Almost 30 crashes reported for 20 customers since app available in store ( Just 2 days)
On 01-Feb-2018 8:45 PM, "Matej Bukovinski" [email protected] wrote:
Looks like the constraints get updated either before the HUD is added to the view hierarchy, or after it is removed. Perhaps a simple if ( self.superView) { return; } at the top of -[MBProgressHUD updateConstraints] would do the trick.
Do you have a way to reproduce this issue?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jdg/MBProgressHUD/issues/522#issuecomment-362296165, or mute the thread https://github.com/notifications/unsubscribe-auth/AA_sw30VtuRdpQA2uivtUXbSTGWMEDp1ks5tQdTzgaJpZM4R1rDM .
@matej I tried with above solution which you posted but I had another crash with above solution. if (self.superView) { return; }
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'The layout constraints still need update after sending -updateConstraints to <MBProgressHUD: 0x7faa10c87970; frame = (0 0; 768 1024); opaque = NO; autoresize = W+H; layer = <CALayer: 0x600000434600>>. MBProgressHUD or one of its superclasses may have overridden -updateConstraints without calling super. Or, something may have dirtied layout constraints in the middle of updating them. Both are programming errors.'
*** First throw call stack: ( 0 CoreFoundation 0x00000001140af12b __exceptionPreprocess + 171 1 libobjc.A.dylib 0x0000000113743f41 objc_exception_throw + 48 2 CoreFoundation 0x0000000114124245 +[NSException raise:format:] + 197 3 UIKit 0x0000000110d03e94 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededCollectingViews:forSecondPass:] + 1296 4 UIKit 0x0000000110d03d13 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededCollectingViews:forSecondPass:] + 911 5 Foundation 0x000000010faee6d1 -[NSISEngine withBehaviors:performModifications:] + 131 6 UIKit 0x0000000110d046c5 _100-[UIView(AdditionalLayoutSupport) updateConstraintsIfNeededWithViewForVariableChangeNotifications:]_block_invoke + 90 7 UIKit 0x0000000110d02f23 -[UIView(AdditionalLayoutSupport) _withUnsatisfiableConstraintsLoggingSuspendedIfEngineDelegateExists:] + 104 8 UIKit 0x0000000110d04234 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededWithViewForVariableChangeNotifications:] + 160 9 UIKit 0x0000000110cf2fa9 -[UIWindow(UIConstraintBasedLayout) _updateConstraintsIfNeededWithViewForVariableChangeNotifications:] + 98 10 UIKit 0x0000000110d0534e -[UIView(AdditionalLayoutSupport) _updateConstraintsAtEngineLevelIfNeededWithViewForVariableChangeNotifications:] + 401 11 UIKit 0x000000011023f3c6 -[UIView(Hierarchy) _updateConstraintsAsNecessaryAndApplyLayoutFromEngine] + 159 12 UIKit 0x0000000110254a6d -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1439 13 QuartzCore 0x0000000112b3a61c -[CALayer layoutSublayers] + 159 14 QuartzCore 0x0000000112b3e7ad _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 401 15 QuartzCore 0x0000000112ac586c _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 364 16 QuartzCore 0x0000000112af2946 _ZN2CA11Transaction6commitEv + 500 17 QuartzCore 0x0000000112af3694 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 76 18 CoreFoundation 0x0000000114051c07 CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 23 19 CoreFoundation 0x0000000114051b5e __CFRunLoopDoObservers + 430 20 CoreFoundation 0x0000000114036124 __CFRunLoopRun + 1572 21 CoreFoundation 0x0000000114035889 CFRunLoopRunSpecific + 409 22 GraphicsServices 0x000000011767d9c6 GSEventRunModal + 62 23 UIKit 0x00000001101835d6 UIApplicationMain + 159 24 testApp 0x000000010cb7f36f main + 111 25 libdyld.dylib 0x0000000115246d81 start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException
[super updateConstraints];
still needs to be called before returning.
Perhaps the setNeedsUpdateConstraints
calls in the class also need to be skipped if we're not yet added to the view hierarchy.
[super updateConstraints]; added this statement before returning. Now, app not crashing but progress hud is not displaying.
@matej Can you please suggest is there any way to fix this issue?
Sorry, the check should be if (self.superView == nil) { return; }
. But it's all just a guess. I can't really tell what underlaying issue here is without debugging this. And I need reproductions steps for that.