Permalink
Browse files

Reject texture replacement mipmaps of the wrong size

  • Loading branch information...
hrydgard committed Dec 5, 2017
1 parent 85b743c commit b3086b14655837b683f957fabdb33282e30da74c
Showing with 15 additions and 3 deletions.
  1. +15 −3 Core/TextureReplacer.cpp
View
@@ -33,7 +33,7 @@
static const std::string INI_FILENAME = "textures.ini";
static const std::string NEW_TEXTURE_DIR = "new/";
static const int VERSION = 1;
static const int MAX_MIP_LEVELS = 64;
static const int MAX_MIP_LEVELS = 12; // 12 should be plenty, 8 is the max mip levels supported by the PSP.
TextureReplacer::TextureReplacer() : enabled_(false), allowVideo_(false), ignoreAddress_(false), hash_(ReplacedTextureHash::QUICK) {
none_.alphaStatus_ = ReplacedTextureAlpha::UNKNOWN;
@@ -293,8 +293,20 @@ void TextureReplacer::PopulateReplacement(ReplacedTexture *result, u64 cachekey,
// We pad files that have been hashrange'd so they are the same texture size.
level.w = (png.width * w) / newW;
level.h = (png.height * h) / newH;
result->levels_.push_back(level);
bool bad = false;
if (i != 0) {
// Check that the mipmap size is correct. Can't load mips of the wrong size.
if (level.w != (result->levels_[0].w >> i)) {
WARN_LOG(G3D, "Replacement mipmap invalid: width=%d, expected=%d (level %d, '%s')", level.w, result->levels_[0].w >> i, i, filename.c_str());
bad = true;
}
if (level.h != (result->levels_[0].h >> i)) {
WARN_LOG(G3D, "Replacement mipmap invalid: height=%d, expected=%d (level %d, '%s')", level.h, result->levels_[0].h >> i, i, filename.c_str());
bad = true;
}
}
if (!bad)
result->levels_.push_back(level);
} else {
ERROR_LOG(G3D, "Could not load texture replacement info: %s - %s", filename.c_str(), png.message);
}

0 comments on commit b3086b1

Please sign in to comment.