* Save/Load the length of the array followed by the array of SL_VAR elements. * @param array The array being manipulated * @param length The length of the array in elements * @param conv VarType type of the atomic array (int, uint8_t, uint64_t, etc.) */
| 1178 | * @param conv VarType type of the atomic array (int, uint8_t, uint64_t, etc.) |
| 1179 | */ |
| 1180 | static void SlArray(void *array, size_t length, VarType conv) |
| 1181 | { |
| 1182 | switch (_sl.action) { |
| 1183 | case SLA_SAVE: |
| 1184 | SlWriteArrayLength(length); |
| 1185 | SlCopyInternal(array, length, conv); |
| 1186 | return; |
| 1187 | |
| 1188 | case SLA_LOAD_CHECK: |
| 1189 | case SLA_LOAD: { |
| 1190 | if (!IsSavegameVersionBefore(SLV_SAVELOAD_LIST_LENGTH)) { |
| 1191 | size_t sv_length = SlReadArrayLength(); |
| 1192 | if (GetVarMemType(conv) == SLE_VAR_NULL) { |
| 1193 | /* We don't know this field, so we assume the length in the savegame is correct. */ |
| 1194 | length = sv_length; |
| 1195 | } else if (sv_length != length) { |
| 1196 | /* If the SLE_ARR changes size, a savegame bump is required |
| 1197 | * and the developer should have written conversion lines. |
| 1198 | * Error out to make this more visible. */ |
| 1199 | SlErrorCorrupt("Fixed-length array is of wrong length"); |
| 1200 | } |
| 1201 | } |
| 1202 | |
| 1203 | SlCopyInternal(array, length, conv); |
| 1204 | return; |
| 1205 | } |
| 1206 | |
| 1207 | case SLA_PTRS: |
| 1208 | case SLA_NULL: |
| 1209 | return; |
| 1210 | |
| 1211 | default: |
| 1212 | NOT_REACHED(); |
| 1213 | } |
| 1214 | } |
| 1215 | |
| 1216 | /** |
| 1217 | * Pointers cannot be saved to a savegame, so this functions gets |
no test coverage detected