Simply add protections when accessing the mip bytes of a texture when provided from a KtxStorage

This commit is contained in:
samcake 2017-05-17 12:36:12 -07:00
parent 2d6c6af37f
commit ab3ea65d54
2 changed files with 13 additions and 2 deletions

View file

@ -210,7 +210,16 @@ PixelsPointer KtxStorage::getMipFace(uint16 level, uint8 face) const {
auto faceSize = _ktxDescriptor->getMipFaceTexelsSize(level, face);
if (faceSize != 0 && faceOffset != 0) {
auto file = maybeOpenFile();
result = file->createView(faceSize, faceOffset)->toMemoryStorage();
if (file) {
auto storageView = file->createView(faceSize, faceOffset);
if (storageView) {
return storageView->toMemoryStorage();
} else {
qWarning() << "Failed to get a valid storageView for faceSize=" << faceSize << " faceOffset=" << faceOffset << "out of valid file " << QString::fromStdString(_filename);
}
} else {
qWarning() << "Failed to get a valid file out of maybeOpenFile " << QString::fromStdString(_filename);
}
}
return result;
}

View file

@ -25,7 +25,9 @@ StoragePointer Storage::createView(size_t viewSize, size_t offset) const {
viewSize = selfSize;
}
if ((viewSize + offset) > selfSize) {
throw std::runtime_error("Invalid mapping range");
return StoragePointer();
//TODO: Disable te exception for now and return an empty storage instead.
//throw std::runtime_error("Invalid mapping range");
}
return std::make_shared<ViewStorage>(shared_from_this(), viewSize, data() + offset);
}