mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-23 20:51:14 +00:00
TOON: Prevent segmentation fault if PAK file is missing
Could be related to ticket #11319 https://bugs.scummvm.org/ticket/11319
This commit is contained in:
parent
3b4810aab4
commit
573c10f0c8
@ -62,7 +62,7 @@ bool Picture::loadPicture(const Common::String &file) {
|
||||
memcpy(_palette, _data + dstsize - (dstsize & 0x7ff), _paletteEntries * 3);
|
||||
_vm->fixPaletteEntries(_palette, _paletteEntries);
|
||||
} else {
|
||||
_palette = 0;
|
||||
_palette = NULL;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -76,6 +76,8 @@ bool Picture::loadPicture(const Common::String &file) {
|
||||
_palette = new uint8[_paletteEntries * 3];
|
||||
memcpy(_palette, fileData + 16, _paletteEntries * 3);
|
||||
_vm->fixPaletteEntries(_palette, _paletteEntries);
|
||||
} else {
|
||||
_palette = NULL;
|
||||
}
|
||||
|
||||
// size can only be 640x400 or 1280x400
|
||||
@ -151,10 +153,12 @@ Picture::~Picture() {
|
||||
void Picture::setupPalette() {
|
||||
debugC(1, kDebugPicture, "setupPalette()");
|
||||
|
||||
if (_useFullPalette)
|
||||
_vm->setPaletteEntries(_palette, 0, 256);
|
||||
else
|
||||
_vm->setPaletteEntries(_palette, 1, 128);
|
||||
if (_palette != NULL) {
|
||||
if (_useFullPalette)
|
||||
_vm->setPaletteEntries(_palette, 0, 256);
|
||||
else
|
||||
_vm->setPaletteEntries(_palette, 1, 128);
|
||||
}
|
||||
}
|
||||
|
||||
void Picture::drawMask(Graphics::Surface &surface, int16 x, int16 y, int16 dx, int16 dy) {
|
||||
|
@ -115,14 +115,14 @@ void Resources::addToCache(const Common::String &packName, const Common::String
|
||||
_resourceCache.push_back(entry);
|
||||
}
|
||||
|
||||
void Resources::openPackage(const Common::String &fileName) {
|
||||
bool Resources::openPackage(const Common::String &fileName) {
|
||||
debugC(1, kDebugResource, "openPackage(%s)", fileName.c_str());
|
||||
|
||||
Common::File file;
|
||||
bool opened = file.open(fileName);
|
||||
|
||||
if (!opened)
|
||||
return;
|
||||
return false;
|
||||
|
||||
PakFile *pakFile = new PakFile();
|
||||
pakFile->open(&file, fileName);
|
||||
@ -130,6 +130,7 @@ void Resources::openPackage(const Common::String &fileName) {
|
||||
file.close();
|
||||
|
||||
_pakFiles.push_back(pakFile);
|
||||
return true;
|
||||
}
|
||||
|
||||
void Resources::closePackage(const Common::String &fileName) {
|
||||
|
@ -75,7 +75,7 @@ class Resources {
|
||||
public:
|
||||
Resources(ToonEngine *vm);
|
||||
~Resources();
|
||||
void openPackage(const Common::String &file);
|
||||
bool openPackage(const Common::String &file);
|
||||
void closePackage(const Common::String &fileName);
|
||||
Common::SeekableReadStream *openFile(const Common::String &file);
|
||||
uint8 *getFileData(const Common::String &fileName, uint32 *fileSize); // this memory must be copied to your own structures!
|
||||
|
@ -1523,7 +1523,13 @@ void ToonEngine::loadScene(int32 SceneId, bool forGameLoad) {
|
||||
Common::String locationName = state()->_locations[SceneId]._name;
|
||||
|
||||
// load package
|
||||
resources()->openPackage(createRoomFilename(locationName + ".PAK"));
|
||||
if (!resources()->openPackage(createRoomFilename(locationName + ".PAK"))) {
|
||||
Common::String msg = Common::String::format(_("Unable to locate the '%s' data file."), createRoomFilename(locationName + ".PAK").c_str());
|
||||
GUIErrorMessage(msg);
|
||||
warning("%s", msg.c_str());
|
||||
_shouldQuit = true;
|
||||
return;
|
||||
}
|
||||
|
||||
loadAdditionalPalette(locationName + ".NPP", 0);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user