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.

Exception in GSNew.hpp (operator delete)

torokze
Participant

Hello,

 

During the adaptation of our addon to the new Archicad 28 Windows, an exception occurs in the function below.

 

 

inline void CCALL operator delete (void *p) noexcept
{
	GS::MemoryManager::Free (p);
}

 

 

 It's a simple std::string deallocation. The string contains valid data.

This exception occurs in Release mode build only, the Debug build runs flawlessly just like the Archicad 26/27 version of the addon. The exception occurs in Archicad 28 Release build only.

 

We have

- Addon.apx

- Addon.Login.CLR.dll (CLR Bridge)

- Addon.WebView.dll (.NET)

The addon displays a login window (.NET) through the CLR and converts a managed string to std::string as return value.

 

torokze_0-1728313656052.png

torokze_1-1728313738462.png

 

Thanks,

Zoltan

9 REPLIES 9

Uff, that's a tough one.
Do you get more info from debugging when compiling in Release mode with debug symbols?
Maybe you can also share the string conversion function for us to take a look.

This is Release mode with debug symbols already.

 

std::string ManagedStringToUTF8String(System::String^ in)
{
    if (!System::String::IsNullOrEmpty(in))
    {
        //std::string str = msclr::interop::marshal_as<std::string>(in); // Don't use this.

        array<Byte>^ bytes = Encoding::UTF8->GetBytes(in);

        pin_ptr<Byte> pinnedBytes = &bytes[0];

        std::string str(reinterpret_cast<char*>(pinnedBytes));

        return str;
    }

    return "";
}

I see, so then my first guess is that it's due to the optimization for Release builds.
You can try /Od or wrap the function (or parts of it) in

#pragma optimize("", off)
...
#pragma optimize("", on)

as suggested here: https://stackoverflow.com/questions/24664865/preventing-the-optimizer-from-optimizing-a-variable-awa...

I use msclr::interop::marshal_as<std::string>(str) in similar cases, but for .net APIs like Revit. I see you've commented "Don't use this" - was there a problem?

Ralph Wessel BArch
Software Engineer Speckle Systems

I tried several ways, none of them worked.

I don't know the reason, it's the work of another developer who no longer works for us.

Ralph Wessel
Mentor

Is there a compelling reason use .net for an Archicad add-on? You are almost certain to hit a significant number of technical issues trying to use this outside a .net context. I recommend either writing everything using the Archicad API and native OS API in C++ (without .net) or writing an independent .net application and talking to an Archicad add-on using the http interface (or similar). Then you don't have to struggle with mixing platforms.

Ralph Wessel BArch
Software Engineer Speckle Systems
Viktor Kovacs
Graphisoft
Graphisoft

This addon is part of an addon package (Archicad/Revit/Navis/Autocad/Tekla). The login module is the same in all of them. It's a .NET dll paired with a CLR wrapper. What's the reason? I don't know, I just maintain the code,