The Global Archicad Community

Stay informed. Get help. Share your knowledge.

Discussions about using GRAPHISOFT's tools (Archicad API, BIMx API, BIMcloud API) for independent software developers

Moderators: Karl Ottenstein, LaszloNagy, ejrolon, Barry Kelly, gkmethy, rmasaki, MOREH Tamas, Akos Somorjai, Ed Brown, Mihály Palenik, Tibor Lorántfy

#316570
Hi,

in our team, we develop an Archicad plugin which uses the Archicad API. Here I encountered the following problem:
When I call the API function ACAPI_Attribute_Modify with a MaterialType attribute shortly before or after I click somewhere on the UI, Archicad crashes.
The values of the material attribute seem to be OK. Calling ACAPI_Attribute_Get immediately before does not cause any problems. Do you have
an idea of what I could do not to make it crash?

Thanks in advance.
#316641
Here is a code example I am able to reconstruct the problem with:
Code: Select all
GSErrCode makeRed(int id)
	{
		API_Attribute attrib;
		BNClear(attrib);

		attrib.header.typeID = API_MaterialID;
		attrib.header.index = API_AttributeIndex(id);
		if (auto err = ACAPI_Attribute_Get(&attrib); err != 0)
		{
			return err;
		}

		attrib.material.emissionAtt = 0;
		attrib.material.emissionRGB = API_RGBColor{0, 0, 0};
		attrib.material.mtype = APIMater_GeneralID;
		attrib.material.specularPc = 74;
		attrib.material.transpAtt = 0;
		attrib.material.transpPc = 0;
		attrib.material.surfaceRGB = API_RGBColor{ 1, 0, 0 };
		IO::Location loc;
		API_Texture texture;
		BNZeroMemory(&texture, sizeof(API_Texture));
		attrib.material.texture = texture;

		return ACAPI_Attribute_Modify(&attrib, NULL);
	}
I run this code and click somewhere in the UI very fast after I started it.
#316646
Could you also tell me:
- Which version of Archicad you're targeting
- On what platform
- With which compiler and version
- And (if using VS) which toolset you're using, or (if Xcode) which C++ dialect you are using, e.g. C++14

I only noticed a couple if unusual things in your code, but they shouldn't cause a crash:
1) This line: IO::Location loc;
The variable "loc" is declared but never used for anything

2) These lines:
API_Texture texture;
BNZeroMemory(&texture, sizeof(API_Texture));
attrib.material.texture = texture;
…could be just:
BNZeroMemory(&attrib.material.texture, sizeof(API_Texture));
#316686
Hello Ralph,

I tried it with Archicad 22, 23, and 24 on Windows. I compile with platform toolset Visual Studio 2019 (v142), C++20

These code findings are due to the fact that I removed some code from my example (of course made sure it still crashes).
#316690
eziebarth wrote:
Fri Sep 18, 2020 7:45 am
I tried it with Archicad 22, 23, and 24 on Windows. I compile with platform toolset Visual Studio 2019 (v142), C++20
These code findings are due to the fact that I removed some code from my example (of course made sure it still crashes).
I suspect the cause of the problem may be due to the VS toolset you're using. It's important to observe the system requirements for each API version, e.g.: http://archicadapi.graphisoft.com/docum ... quirements

For AC22 you need to use the 2015 toolset (v140). For AC23 and 24 you need to use the 2017 toolset (v141). You can do this with VS 2019, but just make sure each target has the correct toolset selected (that's what we do). I would also recommend not exceeding C++14 at the moment – I don't know if this is critical, but GS does this in the API examples.
#316958
Hello Ralph,

Thanks for your advice. I tried it with AC 24 and 2017 toolset (v141). Unfortunately, the crashes still happen. I can try if I can reproduce the crash by using one of the code examples which are delivered with the dev kit. That will take me some time. Would that be helpful?
#316967
It is sometimes difficult to pinpoint the cause of a crash. The API has bugs, but it is rare for this to be the cause and it can require a lot of effort to prove it.

I recommend trying to narrow the code to do as little as possible while still causing a crash. If you find that the crashing stops after a change, that could provide a clue to the source of the problem. It will be very useful if you can reproduce the crash using an API example. If the fault is narrowed to a specific function, forward it to the API support team and they will help to resolve it (either confirming a bug or providing guidance to avoid the problem).

There are many approaches to debugging. A tool that performs bounds checking on all memory accesses could trap memory-handling errors. This is the worst kind of problem because a memory-handling fault does not always cause an immediate crash. The crash (or other odd behaviour) might follow much later.