mirror of https://github.com/OpenTTD/OpenTTD
(svn r1540) -Fix: since grf files are reopened on every load/new game, close the old opened to fix stale filehandles (thx tamlin)
parent
8efc7866dd
commit
340a9ab6be
17
fileio.c
17
fileio.c
|
@ -83,16 +83,20 @@ void FioReadBlock(void *ptr, uint size)
|
||||||
fread(ptr, 1, size, _fio.cur_fh);
|
fread(ptr, 1, size, _fio.cur_fh);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void FioCloseFile(int slot)
|
||||||
|
{
|
||||||
|
if (_fio.handles[slot] != NULL) {
|
||||||
|
fclose(_fio.handles[slot]);
|
||||||
|
_fio.handles[slot] = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void FioCloseAll(void)
|
void FioCloseAll(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i != lengthof(_fio.handles); i++) {
|
for (i = 0; i != lengthof(_fio.handles); i++)
|
||||||
if (_fio.handles[i] != NULL) {
|
FioCloseFile(i);
|
||||||
fclose(_fio.handles[i]);
|
|
||||||
_fio.handles[i] = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FioOpenFile(int slot, const char *filename)
|
void FioOpenFile(int slot, const char *filename)
|
||||||
|
@ -126,6 +130,7 @@ void FioOpenFile(int slot, const char *filename)
|
||||||
if (f == NULL)
|
if (f == NULL)
|
||||||
error("Cannot open file '%s'", buf);
|
error("Cannot open file '%s'", buf);
|
||||||
|
|
||||||
|
FioCloseFile(slot); // if file was opened before, close it
|
||||||
_fio.handles[slot] = f;
|
_fio.handles[slot] = f;
|
||||||
FioSeekToFile(slot << 24);
|
FioSeekToFile(slot << 24);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue