NSWindow beginSheet:completionHandler: presents wrong sheet

Originator:autoreleasepool
Number:rdar://36706596 Date Originated:January 21 2018
Status:Open Resolved:
Product:macOS + SDK Product Version:10.12
Classification:Serious Bug Reproducible:Always
 
NSWindow beginSheet:completionHandler: presents wrong sheet


-NSWindow beginSheet:completionHandler: has a serious bug on systems prior to 10.13 "High Sierra".
we can reproduce the bug reliably on 10.10, 10.11 and 10.12.

basically the problem is this. if you terminate the sheet shown by the new
-beginSheet:completionHandler:
API call with the old method
+NSApp endSheet:
instead of the new method
-NSWindow endSheet:
then the next beginSheet:completionHandler: call may present the wrong sheet, not the one that is passed to it, but the previous one.

here is the short and obvious version of the bug: https://pastebin.com/bJpWgA2B

and attached is a complete ZIP archive of a quite minimal Xcode sample exhibiting the issue. running the app shows a sheet. after clicking a button a second sheet is shown. on high-sierra the correct, second sheet is shown - as this is the one passed to beginSheet:. on older systems the first sheet is shown instead which is obviously not what should happen.

Comments

minimal sample project here https://ufile.io/5fp8y

By autoreleasepool at Jan. 21, 2018, 11:59 a.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!