TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

SwiftUI context menu crash on iOS 14.x

Forums > SwiftUI

@bbcs  

Lately I'm getting following crash while opening a context menu in LazyHStack item inside of LazyVStack: "Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UIPreviewTarget requires that the container view is in a window, but it is not. (container: <SwiftUI.HostingScrollView: 0x106876400>)'".

Anyone can help me out how to avoid this crash issue ?

1      

@bbcs  

Thanks for your answer. Yes, you're right the view is quite complex, I have horizontally scrollable items (LazyHGrid) inside of LazyVStack, something similar to Spotify app. The UI part of the old app was implemented using UIKit and we decided to rewrite it using SwiftUI, unfortunately I cannot post the code. The crash happens randomly while running the app on iPhone (iOS 14.x): I'm opening a context menu for one of the item, there's a preview of that item and the conext menu appears, here's the callstack from Xcode:

#0  0x000000019371edc0 in __exceptionPreprocess ()
#1  0x00000001a827b7a8 in objc_exception_throw ()
#2  0x0000000193620a8c in +[NSException raise:format:arguments:] ()
#3  0x00000001949f84c4 in -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] ()
#4  0x0000000195acf200 in -[UIPreviewTarget initWithContainer:center:transform:] ()
#5  0x0000000195acf31c in -[UIPreviewTarget initWithContainer:center:] ()
#6  0x000000019a457ca0 in specialized UIViewSnapshotResponder.previewTarget<τ_0_0>(host:) ()
#7  0x000000019a123d6c in ContextMenuIdentity.preview(host:) ()
#8  0x000000019a123588 in ContextMenuBridge.targetedPreview(for:) ()
#9  0x000000019a1232d8 in @objc ContextMenuBridge.contextMenuInteraction(_:previewForHighlightingMenuWithConfiguration:) ()
#10 0x00000001966e9368 in -[UIContextMenuInteraction _delegate_previewForDismissingForConfiguration:clientReturnedPreview:] ()
#11 0x00000001966e8d14 in -[UIContextMenuInteraction targetedPreviewForAnimator:dismissingWithStyle:clientReturnedPreview:] ()
#12 0x000000019600d768 in -[_UIContextMenuPresentationAnimation _targetedPreviewForDismissalAnimation] ()
#13 0x000000019600cb1c in __95-[_UIContextMenuPresentationAnimation _actuallyPerformTransitionFromView:toView:containerView:]_block_invoke ()
#14 0x0000000196644af8 in +[UIView(Animation) performWithoutAnimation:] ()
#15 0x000000019600bff8 in -[_UIContextMenuPresentationAnimation _actuallyPerformTransitionFromView:toView:containerView:] ()
#16 0x000000019600d310 in -[_UIContextMenuPresentationAnimation performTransitionFromView:toView:containerView:] ()
#17 0x00000001955dbc20 in __85-[_UIRapidClickPresentationAssistant _animateDismissalWithReason:actions:completion:]_block_invoke_2 ()
#18 0x0000000196646348 in +[UIView _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:] ()
#19 0x000000019664e520 in +[UIView(Internal) _animateWithAnimationAndComposerGetter:animations:completion:animationStateSetup:] ()
#20 0x000000019664dba8 in +[UIView __animateUsingSpringWithDampingRatio:response:interactive:initialDampingRatio:initialResponse:dampingRatioSmoothing:responseSmoothing:targetSmoothing:projectionDeceleration:retargetImpulse:animations:completion:] ()
#21 0x00000001955dc7f0 in -[_UIRapidClickPresentationAssistant _animateUsingFluidSpringWithType:animations:completion:] ()
#22 0x00000001955db9ec in -[_UIRapidClickPresentationAssistant _animateDismissalWithReason:actions:completion:] ()
#23 0x00000001955db2e0 in -[_UIRapidClickPresentationAssistant dismissWithReason:alongsideActions:completion:] ()
#24 0x00000001960798ec in stateMachineSpec_block_invoke_4 ()
#25 0x00000001961b0fec in handleEvent ()
#26 0x000000019607a0d8 in -[_UIClickPresentationInteraction _cancelWithReason:alongsideActions:completion:] ()
#27 0x00000001966e791c in -[UIContextMenuInteraction _previewPlatterPresentationControllerWantsToBeDismissed:withReason:alongsideActions:completion:] ()
#28 0x00000001963b90e0 in -[_UIPreviewPlatterPresentationController contextMenuListView:didSelectElement:] ()
#29 0x0000000195590e94 in -[_UIContextMenuActionsListView _performActionForElement:] ()
#30 0x00000001955907e8 in -[_UIContextMenuActionsListView _handleSelectionGesture:] ()
#31 0x0000000195c4f430 in -[UIGestureRecognizerTarget _sendActionWithGestureRecognizer:] ()
#32 0x0000000195c58d7c in _UIGestureRecognizerSendTargetActions ()
#33 0x0000000195c55994 in _UIGestureRecognizerSendActions ()
#34 0x0000000195c54f04 in -[UIGestureRecognizer _updateGestureForActiveEvents] ()
#35 0x0000000195c490dc in _UIGestureEnvironmentUpdate ()
#36 0x0000000195c48488 in -[UIGestureEnvironment _updateForEvent:window:] ()
#37 0x0000000196156e04 in -[UIWindow sendEvent:] ()
#38 0x00000001961308c0 in -[UIApplication sendEvent:] ()
#39 0x00000001961b9d38 in __dispatchPreprocessedEventFromEventQueue ()
#40 0x00000001961be74c in __processEventQueue ()
#41 0x00000001961b5b4c in __eventFetcherSourceCallback ()
#42 0x000000019369907c in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ ()
#43 0x0000000193698f78 in __CFRunLoopDoSource0 ()
#44 0x000000019369827c in __CFRunLoopDoSources0 ()
#45 0x000000019369225c in __CFRunLoopRun ()
#46 0x00000001936919f4 in CFRunLoopRunSpecific ()
#47 0x00000001aad67734 in GSEventRunModal ()
#48 0x000000019611075c in -[UIApplication _run] ()
#49 0x0000000196115fcc in UIApplicationMain ()
#50 0x000000010491a3dc in main at /Users/bobybacs/Desktop/Projects/audialsios_newdesign/Audials/Audials/main.m:48
#51 0x000000019334dcf8 in start ()

1      

Hacking with Swift is sponsored by String Catalog.

SPONSORED Get accurate app localizations in minutes using AI. Choose your languages & receive translations for 40+ markets!

Localize My App

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.