We value your input!
Please participate in Archicad 28 Home Screen and Tooltips/Quick Tutorials survey

Archicad C++ API
About Archicad add-on development using the C++ API.

signal=11 crash on opening cocoa webview

Anonymous
Not applicable
Hello again

I'm trying to open an cocoa webview into my Archicad add-on and after it opens its possible to browse a web page for a little, and after e few random clicks on links the whole Archicad crashes just like it hits some memory limit or something.. I get this errors in the console.app:

Jun 27 11:56:25 Julians-iMac Archicad 20.app[20357]: ====>GeneralSignalHandler received signal=11

Jun 27 11:56:25 Julians-iMac Archicad 20.app[20357]: ====>GeneralSignalHandler calling OOP handler

Jun 27 11:56:26 Julians-iMac Archicad 20.app[20357]: Archicad [20357] crashed with signal 11. Report written to: /Users/ivan/Library/Application Support/Graphisoft/BugReporting-20/Archicad-20170627(08-49-05)-[20357]-FATAL.rpt

Jun 27 11:56:27 Julians-iMac Archicad 20.app[20357]: ====>GeneralSignalHandler restoring previous handlers

Jun 27 11:56:27 Julians-iMac com.apple.xpc.launchd[1] 
(com.Graphisoft.Archicad.17352[20357]): Service exited due to signal: Segmentation fault: 11 sent by exc handler[0]

Basically all what I'm doing is creating an instance of nswindow and adding a webview into, all done programatically (all seems to work fine without crash on a simple c++ project, but crashes after a while with Archicad API included):

void openWindowAndWebView(void)
{

    
    NSWindow *window =
    [[NSWindow alloc]
     initWithContentRect:NSMakeRect(0, 0, 800, 600) styleMask: NSWindowStyleMaskClosable backing: NSBackingStoreBuffered defer: YES];
    
    [window center];
    window.title = @"Hello World";
    [window makeKeyAndOrderFront:window];
    [window setStyleMask:[window styleMask] | NSWindowStyleMaskTitled | NSWindowStyleMaskResizable];
//
//    Window_delegate *d = [Window_delegate new];
//    window.delegate = d;
//    
    WebView *wb = [[WebView alloc] initWithFrame:window.contentView.frame];
    wb.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
    
    [window.contentView addSubview:wb];
    
    [[wb mainFrame]
     loadRequest:[NSURLRequest
     requestWithURL:[NSURL URLWithString:@"http://www.cars.bg"]]];
    
}

#endif

void openWebView(void){
    WriteReport("Open web view");
#ifdef __OBJC__
    WriteReport("it is OBJC!");
    @autoreleasepool {
        openWindowAndWebView();
    }
#endif
}
I will be very helpful if you can help me, or just guide me how to debug it.

Regards,
Julian
3 REPLIES 3
Ralph Wessel
Mentor
jcimentarov wrote:
I'm trying to open an cocoa webview into my archicad add-on and after it opens its possible to browse a web page for a little, and after e few random clicks on links the whole archicad crashes just like it hits some memory limit or something.
Some more information about the context you're opening the webview into would be useful, e.g. are running this in a separate process to ARCHICAD?

If you're running this in the same thread as the add-on, I'm not surprised it's crashing – I'd only be surprised it worked at all. I think it would play havoc with ARCHICAD's event-handling, memory and window management.
Ralph Wessel BArch
Software Engineer Speckle Systems
Anonymous
Not applicable
GSErrCode __ACENV_CALL MenuCommandHandler (const API_MenuParams *menuParams)
{
    
    
    if (menuParams->menuItemRef.menuResID == 32500) {
        GSErrCode errorCode = ACAPI_CallUndoableCommand ("Importer",
         [&] () -> GSErrCode {
             switch (menuParams->menuItemRef.itemIndex) {
                case  1: openFileDialog(); break;
                case  2: openWebView();break;
                
                default: return NoError;
             }
         });
        
        return errorCode;
    }
    return NoError;
}
This is where I'm calling my method which is opening the window with the webview. I'm still a newbie to c++ and I'm not pretty sure if it runs in a different thread than the add-on. How can I check that, and if it doesn't run in a separate threat how could I fix it?
Akos Somorjai
Graphisoft
Graphisoft
jcimentarov wrote:
GSErrCode __ACENV_CALL MenuCommandHandler (const API_MenuParams *menuParams)
{
    
    
    if (menuParams->menuItemRef.menuResID == 32500) {
        GSErrCode errorCode = ACAPI_CallUndoableCommand ("Importer",
         [&] () -> GSErrCode {
             switch (menuParams->menuItemRef.itemIndex) {
                case  1: openFileDialog(); break;
                case  2: openWebView();break;
                
                default: return NoError;
             }
         });
        
        return errorCode;
    }
    return NoError;
}
This is where I'm calling my method which is opening the window with the webview. I'm still a newbie to c++ and I'm not pretty sure if it runs in a different thread than the add-on. How can I check that, and if it doesn't run in a separate threat how could I fix it?
The menu command handler runs on the main thread.
My guess that here the add-on is unloaded very soon after you call the menu command, so try to call ACAPI_KeepInMemory (true); at the beginning of the MenuCommandHandler.

Best, Akos