SysError on read save
This commit is contained in:
parent
14796097e8
commit
cf708175e8
BIN
Plague.g1a
BIN
Plague.g1a
Binary file not shown.
16
src/save.c
16
src/save.c
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue