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

Constraints crash #148

Open
wojciech-kulik opened this issue Aug 28, 2022 · 12 comments
Open

Constraints crash #148

wojciech-kulik opened this issue Aug 28, 2022 · 12 comments

Comments

@wojciech-kulik
Copy link

First of all, thank you for this nice library, I really like it!

From time to time I get this crash from my app:

Unable to activate constraint with anchors <NSLayoutXAxisAnchor:0x600000fc80c0 "NSLayoutGuide:0x6000023b40e0.trailing"> and <NSLayoutXAxisAnchor:0x600000fc9a80 "NSLayoutGuide:0x6000023b42a0.trailing"> because they have no common ancestor. Does the constraint or its anchors reference items in different view hierarchies? That's illegal.

Fatal Exception: NSGenericException
0  CoreFoundation                 0x105194 (Missing UUID 1643f3d9704937e4b844c0c0a42bde3b)
1  libobjc.A.dylib                0x18e04 (Missing UUID 3d936842590331adb1ae1de4f4b448a6)
2  CoreAutoLayout                 0x2c980 (Missing UUID 84856816715234d88ea3097c2ad163f9)
3  CoreAutoLayout                 0x2cb30 (Missing UUID 84856816715234d88ea3097c2ad163f9)
4  ShortcutRecorder               0xae5c -[SRRecorderControl updateActiveConstraints] + 698 (SRRecorderControl.m:698)
5  ShortcutRecorder               0xa71c __49-[SRRecorderControl endRecordingWithObjectValue:]_block_invoke_2 + 636 (SRRecorderControl.m:636)
6  libsystem_trace.dylib          0x7b90 (Missing UUID 42ebf115c7113f7a95f73be2f0bf0890)
7  ShortcutRecorder               0xa544 -[SRRecorderControl endRecordingWithObjectValue:] + 636 (SRRecorderControl.m:636)
8  libsystem_trace.dylib          0x7b90 (Missing UUID 42ebf115c7113f7a95f73be2f0bf0890)
9  ShortcutRecorder               0xa3b8 -[SRRecorderControl endRecording] + 609 (SRRecorderControl.m:609)
10 ShortcutRecorder               0xdea8 -[SRRecorderControl abortEditing] + 1313 (SRRecorderControl.m:1313)
11 AppKit                         0x102a20 (Missing UUID 07bc3607552a3eb9a9414911c589dbc5)
12 ShortcutRecorder               0x858c -[SRRecorderControl dealloc] + 138 (SRRecorderControl.m:138)
13 libobjc.A.dylib                0xe2b4 (Missing UUID 3d936842590331adb1ae1de4f4b448a6)
14 libobjc.A.dylib                0xab34 (Missing UUID 3d936842590331adb1ae1de4f4b448a6)
15 CoreFoundation                 0x422c4 (Missing UUID 1643f3d9704937e4b844c0c0a42bde3b)
16 Foundation                     0x3534c (Missing UUID 59ff845a05b23b64ae066ef1d6aee83e)
17 AppKit                         0x32014 (Missing UUID 07bc3607552a3eb9a9414911c589dbc5)
18 AppKit                         0x36fc (Missing UUID 07bc3607552a3eb9a9414911c589dbc5)

My app is targeting macOS 11.0 and I'm using ShortcutRecorder 3.3.0. The last noticed crash was on macOS 12.5.1

@Kentzo
Copy link
Owner

Kentzo commented Sep 15, 2022

Are you able to reproduce this crash with the Inspector app? Otherwise, could you come up with a sample app so I could debug the issue?

@wojciech-kulik
Copy link
Author

Unfortunately, I wasn't able to reproduce it :(

@Kentzo
Copy link
Owner

Kentzo commented Sep 15, 2022

Does your app manipulate constraints of subviews in any way?

@wojciech-kulik
Copy link
Author

This issue still occurs from time to time. I don't manipulate constraints. I use this control in settings. I have main NSWindow and whenever user changes a tab I change contentViewController. I also use setFrame on that window.

image

Changing segment just hides some views.

@Kentzo
Copy link
Owner

Kentzo commented Oct 6, 2023

I really want to get it fixed, but I am at a loss where to start. Just doesn't make sense that it crashes only occasionally on a static layout like this.

@wojciech-kulik
Copy link
Author

wojciech-kulik commented Oct 6, 2023

I understand, no worries, I know that there is not much information here. I have never experienced this issue either.

This is the latest stacktrace:

Fatal Exception: NSGenericException
0  CoreFoundation                 0xf28b4 (Missing UUID a68b8c771dbd35b083fe42ad58dd6629)
1  libobjc.A.dylib                0x19eb4 (Missing UUID 1c0364b5d7e33170baa69c28f400e7cc)
2  CoreAutoLayout                 0x2a070 (Missing UUID 864305e982e3397ca9012f78d8edefa4)
3  CoreAutoLayout                 0x2a1e0 (Missing UUID 864305e982e3397ca9012f78d8edefa4)
4  ShortcutRecorder               0xad38 -[SRRecorderControl updateActiveConstraints] + 698 (SRRecorderControl.m:698)
5  ShortcutRecorder               0xa758 __49-[SRRecorderControl endRecordingWithObjectValue:]_block_invoke_2 + 636 (SRRecorderControl.m:636)
6  libsystem_trace.dylib          0x76d8 (Missing UUID 4af0ea7de9f430e7914dfb292edb7f37)
7  ShortcutRecorder               0xa5d0 -[SRRecorderControl endRecordingWithObjectValue:] + 636 (SRRecorderControl.m:636)
8  libsystem_trace.dylib          0x76d8 (Missing UUID 4af0ea7de9f430e7914dfb292edb7f37)
9  ShortcutRecorder               0xa464 -[SRRecorderControl endRecording] + 609 (SRRecorderControl.m:609)
10 ShortcutRecorder               0xd708 -[SRRecorderControl abortEditing] + 1313 (SRRecorderControl.m:1313)
11 AppKit                         0xd44ec (Missing UUID a4e78dd16b6e3f57924a4a6a2e679789)
12 ShortcutRecorder               0x8aa8 -[SRRecorderControl dealloc] + 138 (SRRecorderControl.m:138)
13 libobjc.A.dylib                0xf418 (Missing UUID 1c0364b5d7e33170baa69c28f400e7cc)
14 libobjc.A.dylib                0xbaf0 (Missing UUID 1c0364b5d7e33170baa69c28f400e7cc)
15 CoreFoundation                 0x3c57c (Missing UUID a68b8c771dbd35b083fe42ad58dd6629)
16 Foundation                     0x30e88 (Missing UUID 11eb37ae355b3a35af1b13b599244410)
17 AppKit                         0x2d468 (Missing UUID a4e78dd16b6e3f57924a4a6a2e679789)
18 AppKit                         0x4708 (Missing UUID a4e78dd16b6e3f57924a4a6a2e679789)
19 Snippety                       0x567a4 main + 53 (SnippetyApplication.swift:53)
20 ???                            0x18af49058 (Missing)

Would it be possible to add there some extra check:

4  ShortcutRecorder               0xad38 -[SRRecorderControl updateActiveConstraints] + 698 (SRRecorderControl.m:698)
5  ShortcutRecorder               0xa758 __49-[SRRecorderControl endRecordingWithObjectValue:]_block_invoke_2 + 636 

It is weird because it happens based on stack trace on "endRecording" when nothing actually happens on the view.
Maybe it happens when user is in "recording mode" and closes window or changes tab? But I tried it and it doesn't crash.

The crash says that you are setting constraints with some layout guide. What layout guide it is?

EDIT:

10 ShortcutRecorder               0xd708 -[SRRecorderControl abortEditing] + 1313 (SRRecorderControl.m:1313)
11 AppKit                         0xd44ec (Missing UUID a4e78dd16b6e3f57924a4a6a2e679789)
12 ShortcutRecorder               0x8aa8 -[SRRecorderControl dealloc] + 138 (SRRecorderControl.m:138)

Please take a look here, it looks like it happens during deallocation. Probably the view or something is already detached but the deallocation triggers constraints update?

EDIT2:
I reproduced it! 🎊 That's the case:

  1. Start recording
  2. Close the window
    Occasionally it happens.

EDIT3:
I achieved 100% reproducibility.

  1. Start recording
  2. Switch tab (in case of my app) which detaches the ViewController with the control
  3. Close the window
    The ViewController's view is not in the view hierarchy and deallocation triggers constraints update which crashes the app.

The solution would be probably to avoid constraints update during deallocation :) 🍺

@Kentzo
Copy link
Owner

Kentzo commented Oct 6, 2023

Could you reproduce it in a sample project that you can share? Want to make sure I got it right.

Kentzo added a commit that referenced this issue Oct 6, 2023
@Kentzo
Copy link
Owner

Kentzo commented Oct 6, 2023

Please try the issue-148 branch.

@wojciech-kulik
Copy link
Author

wojciech-kulik commented Oct 7, 2023

I prepared a sample project:
https://github.com/wojciech-kulik/ShortcutRecorderCrash

Steps:

  1. Open new window
  2. Start recording
  3. Detach ViewController
  4. Close the window

If you change in Podfile branch to issue-148, this crash is not reproducible.

@wojciech-kulik
Copy link
Author

@Kentzo when do you think you will be able to release your fix?

@Kentzo
Copy link
Owner

Kentzo commented Oct 9, 2023

Do you need binaries or a tag would suffice?

@wojciech-kulik
Copy link
Author

I'm using CocoaPods. Are you able to release the new version?

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

2 participants