2021-10-15 09:15 AM
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;
Solved! Go to Solution.
2021-10-15 01:44 PM - edited 2021-10-15 03:40 PM
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
2021-10-15 01:44 PM - edited 2021-10-15 03:40 PM
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