From cd8f3e1b0187a524411af0f01742da050f0a28f7 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Thu, 23 Feb 2017 13:04:04 -0800 Subject: [PATCH] Prevent name collisions in KTX from causing crashes --- libraries/gpu/src/gpu/Texture_ktx.cpp | 3 +++ libraries/model/src/model/TextureMap.cpp | 3 +-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/libraries/gpu/src/gpu/Texture_ktx.cpp b/libraries/gpu/src/gpu/Texture_ktx.cpp index 3b56b1e8c5..c7da499e98 100644 --- a/libraries/gpu/src/gpu/Texture_ktx.cpp +++ b/libraries/gpu/src/gpu/Texture_ktx.cpp @@ -117,6 +117,9 @@ ktx::KTXUniquePointer Texture::serialize(const Texture& texture) { } auto ktxBuffer = ktx::KTX::create(header, images); + auto expectedMipCount = texture.evalNumMips(); + assert(expectedMipCount == ktxBuffer->_images.size()); + assert(expectedMipCount == header.numberOfMipmapLevels); assert(0 == memcmp(&header, ktxBuffer->getHeader(), sizeof(ktx::Header))); assert(ktxBuffer->_images.size() == images.size()); diff --git a/libraries/model/src/model/TextureMap.cpp b/libraries/model/src/model/TextureMap.cpp index dd0ae402d5..7b2e363eff 100755 --- a/libraries/model/src/model/TextureMap.cpp +++ b/libraries/model/src/model/TextureMap.cpp @@ -103,8 +103,7 @@ gpu::Texture* cacheTexture(const std::string& name, gpu::Texture* srcTexture, bo } }); - std::string cleanedName = name; - cleanedName = cleanedName.substr(cleanedName.find_last_of((char) '//') + 1); + std::string cleanedName = QUrl::toPercentEncoding(name.c_str()).toStdString(); std::string cacheFilename(ktxCacheFolder.toStdString()); cacheFilename += "/"; cacheFilename += cleanedName;