We value your input! Please participate in Archicad 28 Home Screen and Tooltips/Quick Tutorials survey
2023-09-08 05:06 PM - last edited on 2024-09-17 12:48 PM by Doreena Deng
Is there anyone could help to fix below code to avoid crashing?.
=======
ACAPI_Element element;
element.header.guid = guid;
GSErrCode err = ACAPI_Element_Get(&element);
if (err == NoError)
{
API_Element newelement = {};
API_ElementMemo newmemo = {};
API_ElementMemo memo = {};
BNZeroMemory(&newelement, sizeof(API_Element));
BNZeroMemory(&newmemo, sizeof(API_ElementMemo));
newelement.header.type.typeID = element.header.type.typeID;
GSErrCode err = ACAPI_Element_GetDefaults(&newelement, &newmemo);
newelement.header.guid = element.header.guid;
newelement.header.floorInd = element.header.floorInd;
if (element.header.hasMemo && ACAPI_Element_GetMemo(element.header.guid, &memo, APIMemoMask_All) == NoError)
{
newmemo = memo;
}
err = ACAPI_CallUndoableCommand("Create element", [&]() -> GSErrCode {
return ACAPI_Element_Create(&newelement, &newmemo);
});
}
=============
2023-09-09 10:36 AM
hi newbie, i did not try out your code but i compared it to the maze tutorial. here are my comments:
ACAPI_Element element;
element.header.guid = guid; // from where does this element come from? do you want to copy an existing element?
GSErrCode err = ACAPI_Element_Get(&element); // here you retrieve an existing element, right?
if (err == NoError)
{
API_Element newelement = {};
API_ElementMemo newmemo = {};
API_ElementMemo memo = {};
BNZeroMemory(&newelement, sizeof(API_Element)); // waht ever you retrieved in the first place will get here deleted
BNZeroMemory(&newmemo, sizeof(API_ElementMemo)); // same here. after that call you can be sure that the memory of that element is empty
newelement.header.type.typeID = element.header.type.typeID; // you are using an variable of a deleted objected.
GSErrCode err = ACAPI_Element_GetDefaults(&newelement, &newmemo); // you cant retrieve anything of a deleted element.
newelement.header.guid = element.header.guid;
newelement.header.floorInd = element.header.floorInd;
if (element.header.hasMemo && ACAPI_Element_GetMemo(element.header.guid, &memo, APIMemoMask_All) == NoError)
{
newmemo = memo;
}
err = ACAPI_CallUndoableCommand("Create element", [&]() -> GSErrCode {
return ACAPI_Element_Create(&newelement, &newmemo);
});
}
2023-09-09 02:05 PM
Hi Joel Buehler,
Referring your questions;
1. Yes, the guid from an existing element which I want to copy.
2.
BNZeroMemory(&newelement, sizeof(API_Element));
This is a newly declare element not element, not sure it should use or not.
BTW, I have try to take those 2 lines of BNZ... out but still crashing. Any suggestion?.
Thanks in adv.