License Delivery maintenance is expected to occur on Saturday, November 30, between 8 AM and 11 AM CET. This may cause a short 3-hours outage in which license-related tasks: license key upload, download, update, SSA validation, access to the license pool and Graphisoft ID authentication may not function properly. We apologize for any inconvenience.
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!

walls.png
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
Software Engineer Speckle Systems