We value your input!
Please participate in Archicad 28 Home Screen and Tooltips/Quick Tutorials survey

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