2025-09-12 11:27 AM - edited 2025-09-15 03:33 PM
Hello guys. I was coding the hookers for Archicad 29 and something went wrong. I was following the examples in IFC_Test, and I wrote the code:
I have also executed this code that gave no errors:
IFCAPI::GetHookManager().RegisterPropertyHook(IFCHook::property_hook);
However, for some reason, after the ending of execution of property_hook(), I received this exception error:
I want also to point out that the ifc values were creating fine, without any errors. I was checking it a lot of times through the debugger.
Have someone dealt with this issue before? I would be glad if someone could point me to my mistake. Thank you in advance!
Solved! Go to Solution.
2025-09-25 05:09 PM
It's hard to say without running your exact example myself. But I've successfully compiled and run the IFCHOOK_Test example without crashes.
My first guess is, that you need to make your hook a static function because the function needs to stay available. Something like:
static void IFCHook::PropertyHook1(const ......) {
...
}
Let us know if this solves the issue.
Bernd
2025-09-25 05:36 PM - edited 2025-09-25 05:50 PM
Having the following code:
template<typename TValue>
static void AddProperty(std::vector<IFCAPI::Property>& properties, const GS::UniString& setName, const GS::UniString& name, const GS::UniString& valueType, const TValue& value)
{
auto apiValue = IFCAPI::GetPropertyBuilder().CreateValue(valueType, value);
if (apiValue.IsOk()) {
auto apiProperty = IFCAPI::GetPropertyBuilder().CreatePropertySingleValue(setName, name, *apiValue);
if (apiProperty.IsOk())
properties.emplace_back(*apiProperty);
}
}
static void AddTextProperty(std::vector<IFCAPI::Property>& properties, const GS::UniString& setName, const GS::UniString& name, const GS::UniString& valueType, const GS::UniString& value)
{
AddProperty(properties, setName, name, valueType, value);
}
void IFCHook::PropertyHook1(const IFCAPI::ObjectID& objectID, std::vector<IFCAPI::Property>& properties) noexcept {
AddTextProperty(properties, "Sample Property Set", "Sample Property", "IfcLabel", "Hello from IFC Hook!");
AddProperty(properties, "Sample Property Set", "Sample Integer Property", "IfcInteger", (Int64)12345);
}
void IFCHook::Enable() noexcept {
auto res = IFCAPI::GetHookManager().RegisterPropertyHook(IFCHook::PropertyHook1);
if (!res.IsOk()) {
throw "Unable to register property hook.";
}
}
...still causes a crash. I just place a chair, trying to check out its properties and it crashes.
P.S. IFCHook::PropertyHook1 is already static as it is declared in such a way in IFCHook class.
2025-09-26 04:57 PM
Hm... weird! Can you show the call stack when the crash happens?
2025-09-26
06:23 PM
- last edited on
2025-09-27
09:12 PM
by
Laszlo Nagy
This is where it jumps after finishing the execution of IFCHook::PropertyHook1()
And this is when it is 1 Step Over behind the crash
2025-09-29 10:35 AM
My suspection is that possibly the value that I put into the vector gets disappeared from the std::vector. Hence I get the crash for reading the invalid address.
2025-09-29
10:52 AM
- last edited on
2025-09-30
08:37 PM
by
Laszlo Nagy
Btw. When I copied the entire test code and tried to test it out, it would also crash Archicad for read access violation.
It happens in this loop, on 5th iteration:
static void PropertyHookCommon(const IFCAPI::ObjectID& objectID, std::vector<IFCAPI::Property>& properties, const GS::UniString namePostfix)
{
API_Element apiElement{};
GS::UniString infoString;
if (GetAPIElement(objectID, apiElement, &infoString)) {
// create scheme property after every infoString character
for (auto index : GS::InRange((UIndex)0, infoString.GetLength())) {
if (infoString[index].IsWhiteSpace())
continue;
GS::UniString character = infoString.GetSubstring(index, 1);
GS::UniString propertySetName = "PSet_InfoString";
GS::UniString propertyName = character;
propertySetName.Append(namePostfix);
propertyName.Append(namePostfix);
AddTextProperty(properties, propertySetName, propertyName, "IfcLabel", character);
}
}
}
2025-09-30 08:20 AM
OK, I just saw a possible solution. Are you making a Debug build? Try compiling it as a Release build.
Somebody else seemed to have a very similar problem in AC29 TP and this was their solution. (https://community.graphisoft.com/t5/Graphisoft-Technology-Preview/Crashes-when-invoking-property-hoo...)
This relates to an issue I had a while back with Debug builds. Check this post to see how you can adapt your Debug build once you've confirmed that it was the issue by trying the Release build: https://community.graphisoft.com/t5/Archicad-C-API/Crash-for-GetOrganizationIds-in-DEBUG-builds-link...
2025-09-30 01:40 PM - edited 2025-09-30 01:41 PM
Hello. Yes, it works now with Release build. Thank you a lot! Now I really wonder why my issue appeared in the first place...
I will try fix the Debug now. Thank you and everybody else here a lot!