cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

License delivery maintenance is planned for Saturday, July 26, between 12:00 and 20:00 CEST. During this time, you may experience outages or limited availability across our services, including BIMcloud SaaS, License Delivery, Graphisoft ID (for customer and company management), Graphisoft Store, and BIMx Web Viewer. More details…

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

Save preferences with ACAPI_SetPreferences(ver, size, preferences) where prefs contains a hashtable;

Mihalcea Bogdan
Contributor

I noticed in the DG_Test Example project that the MyPrefs struct is made only from static variables. For some time I am struggling to Debug my code for saving this kind of struct into the preferences. 
In the hashtable below I want to store multiple dialog Item settings, of the same class. I keep getting memory errors. Is this because I am trying to change the memory dynamically, by adding elements to the HashTable?

typedef struct {
	Int32				version;
	API_AttributeIndex	layer;
	API_AttributeIndex	hatchLineType;
	API_AttributeIndex	hatchFill;
	short				hatchPen;
	short				hatchbkgPen;
	short				hatchContPen;
	bool				hatchGlobal;
	bool				hatchWithArea;
	short				filler;
    GS::HashTable<Type1, short> someStuffToKeepHere;//This is what I want to do.
} MyPrefs;
1 ACCEPTED SOLUTION

Accepted Solutions
Solution
Viktor Kovacs
Graphisoft
Graphisoft

Yes, this is because GS::HashTable contains dynamically allocated data. DG_Test just writes it to the preferences based on the static size of the struct:

 

ACAPI_SetPreferences (CURR_ADDON_VERS, sizeof (MyPrefs), (GSPtr) &prefsData);

 

If you have complex structures in your class, you have to serialize it to a binary blob, and write that one in preferences.

 

You can find a detailed explanation here:

https://archicadapi.graphisoft.com/Archicad-maze-generator-add-on-tutorial-part-3

 

View solution in original post

1 REPLY 1
Solution
Viktor Kovacs
Graphisoft
Graphisoft

Yes, this is because GS::HashTable contains dynamically allocated data. DG_Test just writes it to the preferences based on the static size of the struct:

 

ACAPI_SetPreferences (CURR_ADDON_VERS, sizeof (MyPrefs), (GSPtr) &prefsData);

 

If you have complex structures in your class, you have to serialize it to a binary blob, and write that one in preferences.

 

You can find a detailed explanation here:

https://archicadapi.graphisoft.com/Archicad-maze-generator-add-on-tutorial-part-3