Cocoa: Apple-Q calls FormClose twice
Original Reporter info from Mantis: crlab @neurolabusc1
-
Reporter name: Chris Rorden
Original Reporter info from Mantis: crlab @neurolabusc1
- Reporter name: Chris Rorden
Description:
When compiling a Lazarus project to the Cocoa widgetset the 'Quit' item is appended to the main menu, and it is assigned the Apple-Q keyboard shortcut. Choosing the menu item with the mouse calls "FormClose()" (as it should). However, choosing the menu item with Apple-Q calls "FormClose()" twice. This can cause any code in FormClose to be called twice (e.g. saving preferences, freeing arrays).
Steps to reproduce:
Run attached program from command line. Terminating the program by pressing the red dot on the form or choosing "Quit" with the mouse elicits one "FormClose", choosing Apple-Q elicits two calls to FormClose.
procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
writeln('FormClose');
end;
Additional information:
== 1 ==
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
* frame #0: 0x000000010003f121 project1`FORMCLOSE(this=0x0000000100abd130, SENDER=0x0000000100abd130, CLOSEACTION=CAFREE) at unit1.pas:39:3
frame #1: 0x000000010002b8b8 project1`DOCLOSE(this=0x0000000100abd130, CLOSEACTION=CAFREE) at customform.inc:909:23
frame #2: 0x000000010002f0c9 project1`CLOSE(this=0x0000000100abd130) at customform.inc:2147:7
frame #3: 0x00000001001bf12b project1`"-[TCocoaMenuItem_Quit lclItemSelected:]"(self=0x0000000100b38520, _cmd="lclItemSelected:", SENDER=0x0000000100b38520) at cocoawsmenus.pas:444:23
frame #4: 0x00007fff2ba1fb34 AppKit`-[NSApplication(NSResponder) sendAction:to:from:] + 299
frame #5: 0x00007fff2ba74ce2 AppKit`-[NSMenuItem _corePerformAction] + 312
frame #6: 0x00007fff2ba74a5e AppKit`-[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 106
frame #7: 0x00007fff2ba73866 AppKit`-[NSMenu performKeyEquivalent:] + 348
frame #8: 0x00007fff2bee2aaf AppKit`routeKeyEquivalent + 521
frame #9: 0x00007fff2b7758e8 AppKit`-[NSApplication(NSEvent) sendEvent:] + 1072
frame #10: 0x00000001001a13d6 project1`"-[TCocoaApplication sendEvent:]"(self=0x0000000100c19970, _cmd="sendEvent:", THEEVENT=0x0000000100c97310) at cocoaint.pas:530:13
frame #11: 0x00000001001a1ab7 project1`APPRUNMESSAGES(this=0x0000000100f64040, ONLYONE=true, EVENTEXPDATE=0x00007fff89e39548) at cocoaobject.inc:94:7
frame #12: 0x00000001001a1b5c project1`APPWAITMESSAGE(this=0x0000000100f64040) at cocoaobject.inc:122:44
frame #13: 0x000000010003680a project1`IDLE(this=0x0000000100abccd0, WAIT=true) at application.inc:414:7
frame #14: 0x0000000100038a08 project1`HANDLEMESSAGE(this=0x0000000100abccd0) at application.inc:1283:10
frame #15: 0x0000000100038f0c project1`RUNLOOP(this=0x0000000100abccd0) at application.inc:1419:9
frame #16: 0x00000001001a1618 project1`"-[TCocoaApplication nextEventMatchingMask:untilDate:inMode:dequeue:]"(self=0x0000000100c19970, _cmd="nextEventMatchingMask:untilDate:inMode:dequeue:", MASK=18446744073709551615, EXPIRATION=0x00007fff89e39548, MODE="kCFRunLoopDefaultMode", DEQFLAG=true) at cocoaint.pas:598:5
frame #17: 0x00007fff2b764fd4 AppKit`-[NSApplication run] + 658
frame #18: 0x00000001001a1a1b project1`APPRUN(this=0x0000000100f64040, ALOOP=(Proc = <no summary available>, Self = 0x0000000100abccd0)) at cocoaobject.inc:76:5
frame #19: 0x0000000100038eb8 project1`RUN(this=0x0000000100abccd0) at application.inc:1407:21
frame #20: 0x0000000100001d65 project1`PASCALMAIN at project1.lpr:20:3
frame #21: 0x0000000100021749 project1`FPC_SYSTEMMAIN + 41
frame #22: 0x0000000100001cd4 project1`start + 52
== 2 ==
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
* frame #0: 0x000000010003f121 project1`FORMCLOSE(this=0x0000000100abd130, SENDER=0x0000000100abd130, CLOSEACTION=CAFREE) at unit1.pas:39:3
frame #1: 0x000000010002b8b8 project1`DOCLOSE(this=0x0000000100abd130, CLOSEACTION=CAFREE) at customform.inc:909:23
frame #2: 0x000000010002f0c9 project1`CLOSE(this=0x0000000100abd130) at customform.inc:2147:7
frame #3: 0x00000001001bf12b project1`"-[TCocoaMenuItem_Quit lclItemSelected:]"(self=0x0000000100b38520, _cmd="lclItemSelected:", SENDER=0x0000000100b38520) at cocoawsmenus.pas:444:23
frame #4: 0x00007fff2ba1fb34 AppKit`-[NSApplication(NSResponder) sendAction:to:from:] + 299
frame #5: 0x00007fff2ba74ce2 AppKit`-[NSMenuItem _corePerformAction] + 312
frame #6: 0x00007fff2ba74a5e AppKit`-[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 106
frame #7: 0x00007fff2ba73866 AppKit`-[NSMenu performKeyEquivalent:] + 348
frame #8: 0x00007fff2bee2aaf AppKit`routeKeyEquivalent + 521
frame #9: 0x00007fff2b7758e8 AppKit`-[NSApplication(NSEvent) sendEvent:] + 1072
frame #10: 0x00000001001a13d6 project1`"-[TCocoaApplication sendEvent:]"(self=0x0000000100c19970, _cmd="sendEvent:", THEEVENT=0x0000000100c97310) at cocoaint.pas:530:13
frame #11: 0x00007fff2b765005 AppKit`-[NSApplication run] + 707
frame #12: 0x00000001001a1a1b project1`APPRUN(this=0x0000000100f64040, ALOOP=(Proc = <no summary available>, Self = 0x0000000100abccd0)) at cocoaobject.inc:76:5
frame #13: 0x0000000100038eb8 project1`RUN(this=0x0000000100abccd0) at application.inc:1407:21
frame #14: 0x0000000100001d65 project1`PASCALMAIN at project1.lpr:20:3
frame #15: 0x0000000100021749 project1`FPC_SYSTEMMAIN + 41
frame #16: 0x0000000100001cd4 project1`start + 52
Mantis conversion info:
- Mantis ID: 36265
- OS: Darwin
- OS Build: 10.11.6
- Build: 62200
- Platform: MacBook 2012 Retina 13"
- Version: 2.0.7 (SVN)
- Fixed in revision: 62215 (#3930aa17)