Recent

Author Topic: [Solved] Cocoa window showmodal error- 'NSGenericException'  (Read 292 times)

FangQ

  • Full Member
  • ***
  • Posts: 134
[Solved] Cocoa window showmodal error- 'NSGenericException'
« on: September 20, 2023, 07:46:48 pm »
another teething pain for adapting my code to run on 64bit Mac/Cocoa widgetset - so bare with me ...

after solving the OpenGL rendering context error, I now can build my GUI without OpenGL with lazbuild --ws=cocoa --cpu=x86_64 mcxstudio.lpr, however, running the compiled GUI, it still crashed when closing a ShowModal window.

Here is the code for popping up the modal window and retrieve the settings - it runs fine on Windows/Linux/Carbon-i386 version of Mac, but it crashed when the modal window is closed on Cocoa-64bit Mac

does Cocoa support ShowModal? any experience on solving this would be appreciated!

here is the source code when the crash was triggered:

https://github.com/fangq/mcx/blob/1adb6c6a02a3205349e5bb11fabe2e82fd750fe7/mcxstudio/mcxgui.pas#L740-L754
Code: [Select]
     fmNewSession:=TfmNewSession.Create(self);
     fmnewSession.grProgram.Columns:=1;
     if (Sender is TEdit) then begin
         fmnewSession.grProgram.ItemIndex:=grProgram.ItemIndex;
         fmNewSession.edSession.Text:=edSession.Text;
         fmNewSession.Tag:=1;
     end;
     if(fmNewSession.ShowModal= mrOK) then begin
            sessionid:=Trim(fmNewSession.edSession.Text);
            sessiontype:=fmNewSession.grProgram.ItemIndex;
     end else begin
            fmNewSession.Free;
            exit;
     end;
     fmNewSession.Free;

the detailed error information from the system
Code: [Select]
*** Terminating app due to uncaught exception 'NSGenericException', 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.)'

the full message is

Code: [Select]
System Integrity Protection: disabled

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BAD_ACCESS (SIGABRT)
Exception Codes:       KERN_INVALID_ADDRESS at 0x000000000000008c
Exception Note:        EXC_CORPSE_NOTIFY

VM Regions Near 0x8c:
-->
    __TEXT                 000000010d8c0000-000000010dd70000 [ 4800K] r-x/rwx SM=COW  V" [/Users/fangq/space/git/Project/github/mcx/mcxstudio/debug/mcxstudio]

Application Specific Information:
*** Terminating app due to uncaught exception 'NSGenericException', 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.)'
terminating with uncaught exception of type NSException
abort() called

Application Specific Backtrace 1:
0   CoreFoundation                      0x00007fff5557df3b __exceptionPreprocess + 171
1   libobjc.A.dylib                     0x00007fff7c8da942 objc_exception_throw + 48
2   CoreFoundation                      0x00007fff5560e2d5 +[NSException raise:format:] + 197
3   AppKit                              0x00007fff5334b431 _NSRunModal + 484
4   AppKit                              0x00007fff52d2a67d -[NSAlert runModal] + 240
5   mcxstudio                           0x000000010d9e2fd4 COCOAINT_$$_COCOAPROMPTUSER$crcF62BAB40 + 1100
6   mcxstudio                           0x000000010d9e31c0 COCOAINT$_$TCOCOAWIDGETSET_$__$$_PROMPTUSER$crc484A2DB2 + 80
7   mcxstudio                           0x000000010d999fa5 LCLINTF_$$_PROMPTUSER$crc484A2DB2 + 93
8   mcxstudio                           0x000000010d99a591 LCLINTF_$$_PROMPTUSER$crcB76EAC20 + 185
9   mcxstudio                           0x000000010d8e70ce FORMS$_$TAPPLICATION_$__$$_SHOWEXCEPTION$EXCEPTION + 734
10  mcxstudio                           0x000000010d8e61df FORMS$_$TAPPLICATION_$__$$_HANDLEEXCEPTION$TOBJECT + 551
11  mcxstudio                           0x000000010d8e685e FORMS$_$TAPPLICATION_$__$$_RUNLOOP + 158
12  mcxstudio                           0x000000010d9d870d -[TCocoaApplication run] + 53
13  mcxstudio                           0x000000010d9d93a3 COCOAINT$_$TCOCOAWIDGETSET_$__$$_APPRUN$TAPPLICATIONMAINLOOP + 83
14  mcxstudio                           0x000000010d8e67b4 FORMS$_$TAPPLICATION_$__$$_RUN + 100
15  mcxstudio                           0x000000010d8c1389 PASCALMAIN + 146
16  ???                                 0x0000000000000001 0x0 + 1


steps to reproduce the issue (on a Mac computer):

Code: [Select]
git clone https://github.com/fangq/mcx.git
cd mcx/mcxstudio
lazbuild --ws=cocoa --cpu=x86_64 mcxstudio.lpr

cd debug
open mcxstudio.app

then clicking the "New" button the toolbar (first button), type any string as session ID, and click "OK" - the program crashes.

« Last Edit: September 22, 2023, 08:39:38 pm by FangQ »

FangQ

  • Full Member
  • ***
  • Posts: 134
Re: Cocoa ListView fixated at vsReport viewstyle and requires SmallImages
« Reply #1 on: September 22, 2023, 08:39:17 pm »
scratch my question above - after debugging the problem, I found that the error occurred at this line

https://github.com/fangq/mcx/blob/1adb6c6a02a3205349e5bb11fabe2e82fd750fe7/mcxstudio/mcxgui.pas#L775

basically, the TListView object has the LargeImages property set to an ImageList, but the SmallImages property was not set. This was not a problem under the Carbon widgeset, but Cocoa raised an exception. After setting the SmallImages to the same ImageList, I was able to fix the error.

 

TinyPortal © 2005-2018