allocate mem based on state file size instead of current state size
This commit is contained in:
parent
1a2eeef849
commit
4b78e24753
|
@ -793,21 +793,6 @@ void* dc_loadstate_thread(void* p)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if ( ! dc_serialize(&data, &total_size) )
|
||||
{
|
||||
printf("Failed to load state - could not initialize total size\n") ;
|
||||
cleanup_serialize(data) ;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
data = malloc(total_size) ;
|
||||
if ( data == NULL )
|
||||
{
|
||||
printf("Failed to load state - could not malloc %d bytes", total_size) ;
|
||||
cleanup_serialize(data) ;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
filename = get_savestate_file_path();
|
||||
f = fopen(filename.c_str(), "rb") ;
|
||||
|
||||
|
@ -817,6 +802,16 @@ void* dc_loadstate_thread(void* p)
|
|||
cleanup_serialize(data) ;
|
||||
return NULL;
|
||||
}
|
||||
fseek(f, 0, SEEK_END);
|
||||
total_size = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
data = malloc(total_size) ;
|
||||
if ( data == NULL )
|
||||
{
|
||||
printf("Failed to load state - could not malloc %d bytes", total_size) ;
|
||||
cleanup_serialize(data) ;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fread(data, 1, total_size, f) ;
|
||||
fclose(f);
|
||||
|
|
Loading…
Reference in New Issue