- fixed: The demo buffer was allocated with conflicting methods, because M_ReadFile used new whereas the rest of the demo code assumed malloc. Added a new M_ReadFileMalloc function to handle this case without rewriting other things.

This commit is contained in:
Christoph Oelckers 2014-11-25 17:00:17 +01:00
parent 6665ac5837
commit 29ecbac963
3 changed files with 28 additions and 1 deletions

View file

@ -2636,7 +2636,7 @@ void G_DoPlayDemo (void)
{
FixPathSeperator (defdemoname);
DefaultExtension (defdemoname, ".lmp");
M_ReadFile (defdemoname, &demobuffer);
M_ReadFileMalloc (defdemoname, &demobuffer);
}
demo_p = demobuffer;

View file

@ -137,6 +137,32 @@ int M_ReadFile (char const *name, BYTE **buffer)
return length;
}
//
// M_ReadFile (same as above but use malloc instead of new to allocate the buffer.)
//
int M_ReadFileMalloc (char const *name, BYTE **buffer)
{
int handle, count, length;
struct stat fileinfo;
BYTE *buf;
handle = open (name, O_RDONLY | O_BINARY, 0666);
if (handle == -1)
I_Error ("Couldn't read file %s", name);
if (fstat (handle,&fileinfo) == -1)
I_Error ("Couldn't read file %s", name);
length = fileinfo.st_size;
buf = (BYTE*)M_Malloc(length);
count = read (handle, buf, length);
close (handle);
if (count < length)
I_Error ("Couldn't read file %s", name);
*buffer = buf;
return length;
}
//---------------------------------------------------------------------------
//
// PROC M_FindResponseFile

View file

@ -33,6 +33,7 @@ extern FGameConfigFile *GameConfig;
bool M_WriteFile (char const *name, void *source, int length);
int M_ReadFile (char const *name, BYTE **buffer);
int M_ReadFileMalloc (char const *name, BYTE **buffer);
void M_FindResponseFile (void);
// [RH] M_ScreenShot now accepts a filename parameter.