Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FB15103713: Crash on when using toolbarRole(.editor) for my navigationbar #550

Open
migueldeicaza opened this issue Sep 11, 2024 · 0 comments

Comments

@migueldeicaza
Copy link

  • Date: 2024-09-11
  • Resolution: Open
  • Area: SwiftUI
  • OS: iPadOS 18.0 (22A5350a)
  • Type: Incorrect/Unexpected Behavior

Description

I include a self-contained SwiftUI project that exhibits the problem.

Reproduction steps:

  1. Run the scene on device (or simulator, it also happens there).
  2. Wait for the app to launch, observe the text “Demo” on the top left of the navigation bar, and the three icons on the right.
  3. Suspend the application by going home.
  4. Wait two seconds (you can also look at the Xcode output to see the errors raised by autolayout)
  5. Come back to the app

You will notice two things:

  1. The text “Demo” is gone
  2. The icons on the right are gone

Now, if you tap on the down-arrow that used to be attached to “Demo”, you will get a crash, like this:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UIPreviewTarget requires that the container view is in a window, but it is not. (container: <_UITAMICAdaptorView: 0x1045802f0> → <_UINavigationBarTitleControl: 0x104574f80> → <_UINavigationBarContentView: 0x104313370>)'
*** First throw call stack:
(
0 CoreFoundation 0x00000001804b70ec __exceptionPreprocess + 172
1 libobjc.A.dylib 0x000000018008ede8 objc_exception_throw + 72
2 Foundation 0x0000000180e73aa8 _userInfoForFileAndLine + 0
3 UIKitCore 0x0000000185413fd0 -[UIPreviewTarget initWithContainer:center:transform:] + 324
4 UIKitCore 0x0000000185414150 -[UIPreviewTarget initWithContainer:center:] + 44
5 UIKitCore 0x00000001854048f4 -[_UINavigationBarTitleControl _preview] + 148
6 UIKitCore 0x00000001860ab13c -[UIContextMenuInteraction _delegate_previewForHighlightingForConfiguration:] + 136
7 UIKitCore 0x00000001860a8508 -[UIContextMenuInteraction clickPresentationInteraction:previewForHighlightingAtLocation:] + 68
8 UIKitCore 0x0000000185a40180 -[_UIClickPresentationInteraction _prepareInteractionEffect] + 132
9 UIKitCore 0x0000000185a3dcdc -[_UIClickPresentationInteraction clickDriver:didUpdateHighlightProgress:] + 72
10 UIKitCore 0x0000000185b0224c __63-[_UITouchDownClickInteractionDriver _handleGestureRecognizer:]_block_invoke + 104
11 UIKitCore 0x0000000185a3dc78 __59-[_UIClickPresentationInteraction clickDriver:shouldBegin:]_block_invoke_2 + 124
12 UIKitCore 0x00000001860aafa0 __70-[UIContextMenuInteraction _interactionShouldBeginAtPoint:completion:]_block_invoke + 208
13 UIKitCore 0x00000001860ab014 __70-[UIContextMenuInteraction _interactionShouldBeginAtPoint:completion:]_block_invoke_2 + 92
14 UIKitCore 0x00000001860aae8c -[UIContextMenuInteraction _interactionShouldBeginAtPoint:completion:] + 328
15 UIKitCore 0x00000001860a83f4 -[UIContextMenuInteraction _clickPresentationInteraction:shouldBeginWithTouch:completion:] + 180
16 UIKitCore 0x0000000185a3db4c __59-[_UIClickPresentationInteraction clickDriver:shouldBegin:]_block_invoke + 368
17 UIKitCore 0x0000000185a3d998 -[_UIClickPresentationInteraction clickDriver:shouldBegin:] + 316
18 UIKitCore 0x0000000185b021d0 -[_UITouchDownClickInteractionDriver _handleGestureRecognizer:] + 144
19 UIKitCore 0x00000001855d255c -[UIGestureRecognizerTarget _sendActionWithGestureRecognizer:] + 76
20 UIKitCore 0x00000001855d9980 _UIGestureRecognizerSendTargetActions + 88
21 UIKitCore 0x00000001855d727c _UIGestureRecognizerSendActions + 312
22 UIKitCore 0x00000001855d6fd0 -[UIGestureRecognizer _updateGestureForActiveEvents] + 584
23 UIKitCore 0x00000001855ccae8 _UIGestureEnvironmentUpdate + 2596
24 UIKitCore 0x00000001855cbde0 -[UIGestureEnvironment _deliverEvent:toGestureRecognizers:usingBlock:] + 324
25 UIKitCore 0x00000001855cbb2c -[UIGestureEnvironment _updateForEvent:window:] + 156
26 UIKitCore 0x0000000185adcbb8 -[UIWindow sendEvent:] + 2824
27 UIKitCore 0x0000000185abc93c -[UIApplication sendEvent:] + 376
28 UIKitCore 0x0000000185b45664 __dispatchPreprocessedEventFromEventQueue + 1156
29 UIKitCore 0x0000000185b485f4 __processEventQueue + 5592
30 UIKitCore 0x0000000185b409f0 updateCycleEntry + 156
31 UIKitCore 0x0000000185030388 _UIUpdateSequenceRun + 76
32 UIKitCore 0x00000001859d22e8 schedulerStepScheduledMainSection + 168
33 UIKitCore 0x00000001859d1720 runloopSourceCallback + 80
34 CoreFoundation 0x000000018041b324 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 24
35 CoreFoundation 0x000000018041b26c __CFRunLoopDoSource0 + 172
36 CoreFoundation 0x000000018041a9d0 __CFRunLoopDoSources0 + 232
37 CoreFoundation 0x00000001804150b0 __CFRunLoopRun + 788
38 CoreFoundation 0x0000000180414960 CFRunLoopRunSpecific + 536
39 GraphicsServices 0x0000000190183b10 GSEventRunModal + 160
40 UIKitCore 0x0000000185aa2b40 -[UIApplication run] + 796
41 UIKitCore 0x0000000185aa6d38 UIApplicationMain + 124
42 SwiftUI 0x00000001d1e2eab4 $s7SwiftUI17KitRendererCommon33_ACC2C5639A7D76F611E170E831FCA491LLys5NeverOyXlXpFAESpySpys4Int8VGSgGXEfU
+ 164
43 SwiftUI 0x00000001d1e2e7dc $s7SwiftUI6runAppys5NeverOxAA0D0RzlF + 84
44 SwiftUI 0x00000001d1b70c8c $s7SwiftUI3AppPAAE4mainyyFZ + 148
45 ToolbarCrash.debug.dylib 0x00000001033252b0 $s12ToolbarCrash0aB3AppV5$mainyyFZ + 40
46 ToolbarCrash.debug.dylib 0x0000000103325360 __debug_main_executable_dylib_entry_point + 12
47 dyld 0x0000000103475410 start_sim + 20
48 ??? 0x0000000102dee154 0x0 + 4343128404
49 ??? 0x0421000000000000 0x0 + 297519050383163392
)

The sample program is this:

Files

Sample.swift

//
//  ContentView.swift
//  ToolbarCrash
//
//  Created by Miguel de Icaza on 9/11/24.
//

import SwiftUI

struct ContentView: View {
    @State var sidebarVisibility: NavigationSplitViewVisibility = .detailOnly
    @State var preferredColumn = NavigationSplitViewColumn.detail

    var mybody: some View {
        VStack {
            HStack (alignment: .top){
                Text ("              ^^^^^ \n" +
                      "After swithching back,\nthe text `Demo` will vanish\nAnd tapping the menu will crash")
                Spacer()
                VStack (alignment: .trailing){
                    Text ("The last two icons in the bar will vanish: ^^^^^^^^   ")
                    Image(systemName: "ellipsis.circle")
                    Image(systemName: "info")
                }
            }
            Spacer()
            Text ("To reproduce the bug, go to the home screen, wait 2 seconds and come back here.\nThere will be visual glitches (text vanishing, icons vanishing), and if you tap the menu, it will crash.\nThere will be some errors displayed on the Xcode console")
            Spacer()
        }
    }

    var body: some View {
        NavigationSplitView (columnVisibility: $sidebarVisibility, preferredCompactColumn: $preferredColumn) {
            Text ("Sidebar")
        } detail: {
            mybody
                .navigationBarTitleDisplayMode(.inline)
                .toolbarRole(.editor)
                .toolbar {
                    ToolbarTitleMenu {
                        Button (action: {}) {
                            Label("New Scene", systemImage: "movieclapper")
                        }
                        Button (action: {  }) {
                            Text ("Open")
                        }
                        Button (action: {
                        }) {
                            Text("Close Project")
                        }
                    }
    
                    // Debugging pad
                    ToolbarItemGroup (placement: .primaryAction) {
                        Menu {
                            Button ("Item 1") {
                            }
                        } label: {
                            Label ("Run", systemImage: "play")
                        } primaryAction: {
                        }
    
                        Button (action: { }) {
                            Image (systemName: "info.circle")
                        }
                        Menu {
                            Button (action: {  }) {
                                Text ("Project Settings")
                            }
                            Button (action: {  }) {
                                Label("Reference Guide", systemImage: "book")
                            }
                        } label: {
                            Image (systemName: "ellipsis.circle")
                        }
                    }

                    ToolbarItemGroup (placement: .secondaryAction) {
                        Button (action: {
                        }) {
                            Label("3D", systemImage: "view.3d")
    
                        }
                    }
                    ToolbarItem(placement: .principal) {
                        Text ("Demo")
                    }
                }
        }
    }
}

#Preview {
    ContentView()
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant