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

Archicad crashes when using API_WallRelation

Anonymous
Not applicable
Hello,

I'm developing an Add-on that generates some information from a selected wall. For that, I need information on the connections of a wall. I've been using the API_WallRelation and, for the most part of the cases, everything works fine (conBeg, conEnd and con types of connection).

But, for the highlighted wall on the attached image, I need to use the conRef type of connection (from docs: "walls connected with their reference line to the beginning or the end point of the wall"). In this case, the wall has two connections (one at the beginning and the other one at the end). When I access the second conRef connection, Archicad crashes. Here's the code:

	API_WallRelation wallRelation;
	BNZeroMemory(&wallRelation, sizeof(API_WallRelation));
	ACAPI_Element_GetRelations(guid, API_WallID, (void*) &wallRelation);
	...
	if (wallRelation.nConRef == 2) {
		API_Element wallBegin;
		API_Element wallEnd;
		if (wallRelation.conRef[0]->conWithBeg) {
			wallBegin = FindWall(wallRelation.conRef[0]->guid);
			// Crashes here...
			wallEnd = FindWall(wallRelation.conRef[1]->guid);
		} else {
			// Or Crashes here...
			wallBegin = FindWall(wallRelation.conRef[1]->guid);
			wallEnd = FindWall(wallRelation.conRef[0]->guid);
		}
		...
	}
I've kept only the relevant parts of the code. It seems to me that the pointer returned by wallRelation.conRef[1] is invalid for some reason. Is this a bug in the API or am I doing something wrong?

I'm using the API DevKit 14.2550 on macOS X 10.6.8.

Thanks!
1 REPLY 1
Ralph Wessel
Mentor
Andre wrote:
It seems to me that the pointer returned by wallRelation.conRef[1] is invalid for some reason. Is this a bug in the API or am I doing something wrong?
wallRelation.conRef is a handle, so you need to first dereference the handle and then subscript into the item you need. So rather than this:
wallRelation.conRef[1]->guid
...you need to do this:
(*wallRelation.conRef)[1].guid
Ralph Wessel BArch