We value your input! Please participate in Archicad 28 Home Screen and Tooltips/Quick Tutorials survey
2024-10-08 08:30 AM
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.
Thanks,
Zoltan
2024-10-08 11:31 AM
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.
2024-10-08 02:33 PM
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 "";
}
2024-10-08 02:58 PM
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...
2024-10-08 11:17 PM
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?
2024-10-11 08:21 AM
I tried several ways, none of them worked.
2024-10-11 08:23 AM
I don't know the reason, it's the work of another developer who no longer works for us.
2024-10-11 08:53 AM
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.
2024-10-11 08:01 PM
Please check this article, it may be related:
2024-10-13 10:36 AM
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,