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

AC crashes

Anonymous
Not applicable
Hello,
Im trying to develop something, and first of all need to access floor id.
I tried this code:

	API_WorkspaceInfo	workspaceInfo;
	API_StoryInfo		storyInfo;
	API_ProjectInfo		projectInfo;
	GSErrCode			err;
	Int32				 ind;
	err = ACAPI_Environment (APIEnv_ProjectID, &projectInfo, NULL);
	err = ACAPI_Environment (APIEnv_UserWorkspaceID, &workspaceInfo, &projectInfo.userId);
	BNZeroMemory (&storyInfo, sizeof (API_StoryInfo));
	ACAPI_Environment (APIEnv_GetStorySettingsID, &storyInfo, NULL);
	ind = (*workspaceInfo.stories);
	
	//ACAPI_WriteReport("", );
	
	ACAPI_WriteReport( " "+(*storyInfo.data)[storyInfo.firstStory].floorId, true);
When I run the built add-on, through AC, the program crushes (bug report).

What am I doing wrong?
Is there another way to access this kind of information? (story information)

Thanks a lot!
6 REPLIES 6
Ralph Wessel
Mentor
zanzibar wrote:
Hello,
Im trying to develop something, and first of all need to access floor id.
I tried this code: ...etc... When I run the built add-on, through AC, the program crushes (bug report).
Is there another way to access this kind of information? (story information)
I've answered your question about retrieving storey information in another post. Just a few comments about your code:
  • 1. You should always zero out all structures before using them with API functions. You did this for storeyInfo, but not projectInfo or workspaceInfo.

    2. You aren't checking the error code returned by these function calls. If any of them fail, you should not expect the returned values to be valid or meaningful.

    3. What are you expecting the addition operator to do in the first parameter passed to ACAPI_WriteReport? Do you realise that the expression " " is a const char*, i.e. a pointer, and that adding an integer will result in a pointer to a non-specific memory address?

    4. Where did the variable i come from (line 10)? Is this a sensible subscript value?

    5. Don't forget to release any memory allocated by these functions, e.g. the storey array returned by APIEnv_GetStorySettingsID. Otherwise, you will suffer serious memory leaks.
Ralph Wessel BArch
Anonymous
Not applicable
Well, I guess that its because im not used to this platform.
I actually used the BNZeroMemory function because I saw that the example scripts use it, and I even tried to understand what it means, but it didnt work well. do u have any idea how to explain me that in a simpler way?
And I didnt really catch what u meant in par 4.

Thanks for ur attention!
Ralph Wessel
Mentor
zanzibar wrote:
Well, I guess that its because im not used to this platform.
I actually used the BNZeroMemory function because I saw that the example scripts use it, and I even tried to understand what it means, but it didnt work well. do u have any idea how to explain me that in a simpler way?
And I didnt really catch what u meant in par 4.
Thanks for ur attention!
I think you need to take a course in C/C++ (or study the subject). A C programmer would not expect to be able to write:
"1 + 1 = " + 2;
That's something you might do with BASIC.

Similarly, BNZeroMemory should be immediately familiar to you. It's basically the same as using memset to fill a block of memory with zero values.

My 4th point was referring to the following line:
ind = (*workspaceInfo.stories);
Where does the subscript value i come from? Does its value fit within the array bounds?
Ralph Wessel BArch
Anonymous
Not applicable
The "i" value comes from a loop that runs this function for each floor, I assumed that 0,1,2 and so on are floor indexes.
Ralph Wessel
Mentor
zanzibar wrote:
The "i" value comes from a loop that runs this function for each floor, I assumed that 0,1,2 and so on are floor indexes.
I assumed so, but it would have been very helpful if you had left the loop in your sample code. Loops and subscript variables are common sources of hanging/crashing problems. I'm also assuming your loop begins just after the call to APIEnv_GetStorySettingsID?
Ralph Wessel BArch
Anonymous
Not applicable
Well, youv'e helped me a lot, thx!!!