NSGenericException with runModal on startup, Scrivener 3, Mac OS HIgh Sierra

Hi Guys

I’m getting this error on startup, running Scrivener 3.0 on Mac OS High Sierra. It looks like a popup modal is failing or causing a problem:

Exception Name: NSGenericException

Exception Reason: -[NSAlert runModal] may not be invoked inside of transaction begin/commit pair, or inside of transaction commit (usually this means it was invoked inside of a view’s -drawRect: method.)

Full details:

0 CoreFoundation 0x00007fff3f66e2fb __exceptionPreprocess + 171
1 libobjc.A.dylib 0x00007fff65fdfc76 objc_exception_throw + 48
2 CoreFoundation 0x00007fff3f6ffd6d +[NSException raise:format:] + 205
3 AppKit 0x00007fff3d4c9319 _NSRunModal + 484
4 AppKit 0x00007fff3cea97ad -[NSAlert runModal] + 240
5 ScrAppKit 0x000000010c9e6358 KBRunAlertPanel + 434
6 Scrivener 0x000000010c397938 Scrivener + 125240
7 Scrivener 0x000000010c3885dc Scrivener + 62940
8 CoreFoundation 0x00007fff3f5fdcbc CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER + 12
9 CoreFoundation 0x00007fff3f5fdbaa _CFXRegistrationPost + 442
10 CoreFoundation 0x00007fff3f5fd8f2 ___CFXNotificationPost_block_invoke + 50
11 CoreFoundation 0x00007fff3f5bb6d0 -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1664
12 CoreFoundation 0x00007fff3f5ba803 _CFXNotificationPost + 595
13 Foundation 0x00007fff4167d477 -[NSNotificationCenter postNotificationName:object:userInfo:] + 66
14 AppKit 0x00007fff3cd26f69 -[NSWindow _changeKeyAndMainLimitedOK:] + 940
15 AppKit 0x00007fff3cdd4522 -[NSWindow _makeKeyRegardlessOfVisibility] + 108
16 AppKit 0x00007fff3cd29f78 NSPerformVisuallyAtomicChange + 146
17 AppKit 0x00007fff3cdd4459 -[NSWindow makeKeyAndOrderFront:] + 90
18 Scrivener 0x000000010c3884c3 Scrivener + 62659
19 AppKit 0x00007fff3d15a1a5 __80-[NSDocumentController openDocumentWithContentsOfURL:display:completionHandler:]_block_invoke.1039 + 169
20 AppKit 0x00007fff3d169fe4 ___NSMainRunLoopPerformBlock_block_invoke + 25
21 CoreFoundation 0x00007fff3f60668c CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK + 12
22 CoreFoundation 0x00007fff3f5e90a3 __CFRunLoopDoBlocks + 275
23 CoreFoundation 0x00007fff3f5e8e68 __CFRunLoopRun + 3128
24 CoreFoundation 0x00007fff3f5e7fa3 CFRunLoopRunSpecific + 483
25 HIToolbox 0x00007fff3e907866 RunCurrentEventLoopInMode + 286
26 HIToolbox 0x00007fff3e9074df ReceiveNextEventCommon + 366
27 HIToolbox 0x00007fff3e907354 _BlockUntilNextEventMatchingListInModeWithFilter + 64
28 AppKit 0x00007fff3cc04a23 _DPSNextEvent + 2085
29 AppKit 0x00007fff3d399e6c -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 3044
30 AppKit 0x00007fff3cbf9831 -[NSApplication run] + 764
31 AppKit 0x00007fff3cbc89d2 NSApplicationMain + 804
32 libdyld.dylib 0x00007fff66bce145 start + 1
33 ??? 0x0000000000000001 0x0 + 1

Cheers :smiley:

Thanks, I’ve seen this one crop up in the automatic exception reports that get sent to me, and I think I’ve fixed it for the next update. Essentially, when the main window comes to the foreground, Scrivener runs some checks, and these checks can result in an alert panel appearing in some situations. For instance, when a main project window comes to the foreground, Scrivener checks to see if any changes have been made to the project on iOS, and if so, prompts the user to sync.

However, it seems Apple broke this in 10.13. In 10.13, if you run certain operations - such as showing a “modal” panel - when the window comes to the foreground, this exception gets thrown. This seems like very bad behaviour in macOS to me, since running checks and showing messages when a window is brought forward is a perfectly reasonable thing to do. The fix (I found other developers with the same problem) seems to be to push the checks to the end of the run loop after the window comes to the foreground.

I haven’t been able to test the fix, however, simply because I have never seen this issue myself. Which version of High Sierra are you on? 10.13.1? And are you consistently seeing this error? Can you reproduce it reliably? If so I could send you a build to test the fix.

Thanks,
Keith