SysError on read save

This commit is contained in:
Shadow15510 2021-06-03 18:42:45 +02:00
parent 14796097e8
commit cf708175e8
2 changed files with 11 additions and 5 deletions

Binary file not shown.

View File

@ -15,7 +15,7 @@ void read_save(struct game *current_game)
// Sizes of data
const int planes_size = sizeof(*current_game->planes);
struct plane *planes = current_game->planes;
struct plane *planes[NB_PLANES + 1];
const int data_size = current_game->grid.width * current_game->grid.height;
uint8_t *data = current_game->grid.data;
@ -37,12 +37,15 @@ void read_save(struct game *current_game)
fd = BFile_Open(filename, BFile_ReadOnly);
BFile_Read(fd, current_game, sizeof(*current_game), 0);
Bfile_Read(fd, planes, planes_size, -1);
BFile_Read(fd, planes, planes_size, -1);
BFile_Read(fd, data, data_size, -1);
BFile_Close(fd);
current_game->planes = planes;
for (int i = 0; planes[i]; i ++)
{
current_game->planes[i] = planes[i];
}
current_game->grid.data = data;
}
}
@ -55,7 +58,7 @@ void write_save(const struct game *current_game)
// Create a new savefile
const int data_size = current_game->grid.width * current_game->grid.height;
const int planes_size = sizeof(*current_game->planes);
const int planes_size = NB_PLANES * sizeof(struct plane);
int size = sizeof(*current_game) + planes_size + data_size;
BFile_Remove(filename);
@ -63,7 +66,10 @@ void write_save(const struct game *current_game)
// Write data
BFile_Write(fd, current_game, sizeof(*current_game));
BFile_Write(fd, current_game->planes, planes_size);
for (int i = 0; current_game->planes[i] ; i ++)
{
BFile_Write(fd, current_game->planes[i], sizeof(struct plane));
}
BFile_Write(fd, current_game->grid.data, data_size);
// Close file