diff options
author | Torbjörn Andersson | 2006-05-20 13:59:31 +0000 |
---|---|---|
committer | Torbjörn Andersson | 2006-05-20 13:59:31 +0000 |
commit | 05814a14582eca7bd00e39b3bd8bf5783ddf4f13 (patch) | |
tree | 5a53c57399ac69f3fb0aee44f4eedee3886d77a4 /engines/scumm | |
parent | 3e973d2a910366834931bcf940cdf1f87ab6c96c (diff) | |
download | scummvm-rg350-05814a14582eca7bd00e39b3bd8bf5783ddf4f13.tar.gz scummvm-rg350-05814a14582eca7bd00e39b3bd8bf5783ddf4f13.tar.bz2 scummvm-rg350-05814a14582eca7bd00e39b3bd8bf5783ddf4f13.zip |
Apparently, passing a file handle directly to a function causes that file
handle (a copy of the original?) to be destroyed at the end of the function,
and that closes the internal file handle, even though we want it to stay open.
Who am I to argue with how C++ handles its parameters? I've simply changed the
functions to take pointers to file handles instead. Seems to fix crashes in the
Macintosh resource extractor for me.
svn-id: r22546
Diffstat (limited to 'engines/scumm')
-rw-r--r-- | engines/scumm/he/resource_he.cpp | 66 | ||||
-rw-r--r-- | engines/scumm/he/resource_he.h | 6 |
2 files changed, 36 insertions, 36 deletions
diff --git a/engines/scumm/he/resource_he.cpp b/engines/scumm/he/resource_he.cpp index 8cbb2f263f..2357ec0638 100644 --- a/engines/scumm/he/resource_he.cpp +++ b/engines/scumm/he/resource_he.cpp @@ -1310,13 +1310,13 @@ int MacResExtractor::extractResource(int id, byte **buf) { // we haven't calculated it if (_resOffset == -1) { - if (!init(in)) + if (!init(&in)) error("Resource fork is missing in file '%s'", _fileName.c_str()); in.close(); in.open(_fileName); } - *buf = getResource(in, "crsr", 1000 + id, &size); + *buf = getResource(&in, "crsr", 1000 + id, &size); in.close(); @@ -1335,14 +1335,14 @@ int MacResExtractor::extractResource(int id, byte **buf) { #define MBI_RFLEN 87 #define MAXNAMELEN 63 -bool MacResExtractor::init(Common::File in) { +bool MacResExtractor::init(Common::File *in) { byte infoHeader[MBI_INFOHDR]; int32 data_size, rsrc_size; int32 data_size_pad, rsrc_size_pad; int filelen; - filelen = in.size(); - in.read(infoHeader, MBI_INFOHDR); + filelen = in->size(); + in->read(infoHeader, MBI_INFOHDR); // Maybe we have MacBinary? if (infoHeader[MBI_ZERO1] == 0 && infoHeader[MBI_ZERO2] == 0 && @@ -1365,12 +1365,12 @@ bool MacResExtractor::init(Common::File in) { if (_resOffset == -1) // MacBinary check is failed _resOffset = 0; // Maybe we have dumped fork? - in.seek(_resOffset); + in->seek(_resOffset); - _dataOffset = in.readUint32BE() + _resOffset; - _mapOffset = in.readUint32BE() + _resOffset; - _dataLength = in.readUint32BE(); - _mapLength = in.readUint32BE(); + _dataOffset = in->readUint32BE() + _resOffset; + _mapOffset = in->readUint32BE() + _resOffset; + _dataLength = in->readUint32BE(); + _mapLength = in->readUint32BE(); // do sanity check if (_dataOffset >= filelen || _mapOffset >= filelen || @@ -1387,8 +1387,8 @@ bool MacResExtractor::init(Common::File in) { return true; } -byte *MacResExtractor::getResource(Common::File in, const char *typeID, int16 resID, int *size) { - int i; +byte *MacResExtractor::getResource(Common::File *in, const char *typeID, int16 resID, int *size) { + int i; int typeNum = -1; int resNum = -1; byte *buf; @@ -1412,37 +1412,37 @@ byte *MacResExtractor::getResource(Common::File in, const char *typeID, int16 re if (resNum == -1) return NULL; - in.seek(_dataOffset + _resLists[typeNum][resNum].dataOffset); + in->seek(_dataOffset + _resLists[typeNum][resNum].dataOffset); - len = in.readUint32BE(); + len = in->readUint32BE(); buf = (byte *)malloc(len); - in.read(buf, len); + in->read(buf, len); *size = len; return buf; } -void MacResExtractor::readMap(Common::File in) { +void MacResExtractor::readMap(Common::File *in) { int i, j, len; - in.seek(_mapOffset + 22); + in->seek(_mapOffset + 22); - _resMap.resAttr = in.readUint16BE(); - _resMap.typeOffset = in.readUint16BE(); - _resMap.nameOffset = in.readUint16BE(); - _resMap.numTypes = in.readUint16BE(); + _resMap.resAttr = in->readUint16BE(); + _resMap.typeOffset = in->readUint16BE(); + _resMap.nameOffset = in->readUint16BE(); + _resMap.numTypes = in->readUint16BE(); _resMap.numTypes++; - in.seek(_mapOffset + _resMap.typeOffset + 2); + in->seek(_mapOffset + _resMap.typeOffset + 2); _resTypes = new ResType[_resMap.numTypes]; for (i = 0; i < _resMap.numTypes; i++) { - in.read(_resTypes[i].id, 4); + in->read(_resTypes[i].id, 4); _resTypes[i].id[4] = 0; - _resTypes[i].items = in.readUint16BE(); - _resTypes[i].offset = in.readUint16BE(); + _resTypes[i].items = in->readUint16BE(); + _resTypes[i].offset = in->readUint16BE(); _resTypes[i].items++; } @@ -1450,15 +1450,15 @@ void MacResExtractor::readMap(Common::File in) { for (i = 0; i < _resMap.numTypes; i++) { _resLists[i] = new Resource[_resTypes[i].items]; - in.seek(_resTypes[i].offset + _mapOffset + _resMap.typeOffset); + in->seek(_resTypes[i].offset + _mapOffset + _resMap.typeOffset); for (j = 0; j < _resTypes[i].items; j++) { ResPtr resPtr = _resLists[i] + j; - resPtr->id = in.readUint16BE(); - resPtr->nameOffset = in.readUint16BE(); - resPtr->dataOffset = in.readUint32BE(); - in.readUint32BE(); + resPtr->id = in->readUint16BE(); + resPtr->nameOffset = in->readUint16BE(); + resPtr->dataOffset = in->readUint32BE(); + in->readUint32BE(); resPtr->name = 0; resPtr->attr = resPtr->dataOffset >> 24; @@ -1467,12 +1467,12 @@ void MacResExtractor::readMap(Common::File in) { for (j = 0; j < _resTypes[i].items; j++) { if (_resLists[i][j].nameOffset != -1) { - in.seek(_resLists[i][j].nameOffset + _mapOffset + _resMap.nameOffset); + in->seek(_resLists[i][j].nameOffset + _mapOffset + _resMap.nameOffset); - len = in.readByte(); + len = in->readByte(); _resLists[i][j].name = new byte[len + 1]; _resLists[i][j].name[len] = 0; - in.read(_resLists[i][j].name, len); + in->read(_resLists[i][j].name, len); } } } diff --git a/engines/scumm/he/resource_he.h b/engines/scumm/he/resource_he.h index 976511a974..ec561db5c3 100644 --- a/engines/scumm/he/resource_he.h +++ b/engines/scumm/he/resource_he.h @@ -511,9 +511,9 @@ public: private: int extractResource(int id, byte **buf); - bool init(Common::File in); - void readMap(Common::File in); - byte *getResource(Common::File in, const char *typeID, int16 resID, int *size); + bool init(Common::File *in); + void readMap(Common::File *in); + byte *getResource(Common::File *in, const char *typeID, int16 resID, int *size); int convertIcons(byte *data, int datasize, byte **cursor, int *w, int *h, int *hotspot_x, int *hotspot_y, int *keycolor, byte **palette, int *palSize); |