diff --git a/Source/Engine/Graphics/Textures/GPUTexture.cpp b/Source/Engine/Graphics/Textures/GPUTexture.cpp index ccdf4be95..403f545ba 100644 --- a/Source/Engine/Graphics/Textures/GPUTexture.cpp +++ b/Source/Engine/Graphics/Textures/GPUTexture.cpp @@ -480,6 +480,16 @@ bool GPUTexture::Init(const GPUTextureDescription& desc) break; } } + const bool isCompressed = PixelFormatExtensions::IsCompressed(desc.Format); + if (isCompressed) + { + const int32 blockSize = PixelFormatExtensions::ComputeBlockSize(desc.Format); + if (desc.Width < blockSize || desc.Height < blockSize) + { + LOG(Warning, "Cannot create texture. Invalid dimensions. Description: {0}", desc.ToString()); + return true; + } + } // Release previous data ReleaseGPU(); @@ -487,7 +497,7 @@ bool GPUTexture::Init(const GPUTextureDescription& desc) // Initialize _desc = desc; _sRGB = PixelFormatExtensions::IsSRGB(desc.Format); - _isBlockCompressed = PixelFormatExtensions::IsCompressed(desc.Format); + _isBlockCompressed = isCompressed; if (OnInit()) { ReleaseGPU(); diff --git a/Source/Engine/Graphics/Textures/StreamingTexture.cpp b/Source/Engine/Graphics/Textures/StreamingTexture.cpp index 015386fff..09552ec06 100644 --- a/Source/Engine/Graphics/Textures/StreamingTexture.cpp +++ b/Source/Engine/Graphics/Textures/StreamingTexture.cpp @@ -114,9 +114,9 @@ bool StreamingTexture::Create(const TextureHeader& header) { // Ensure that streaming doesn't go too low because the hardware expects the texture to be min in size of compressed texture block int32 lastMip = header.MipLevels - 1; - while ((header.Width >> lastMip) < 4 && (header.Height >> lastMip) < 4) + while ((header.Width >> lastMip) < 4 && (header.Height >> lastMip) < 4 && lastMip > 0) lastMip--; - _minMipCountBlockCompressed = header.MipLevels - lastMip + 1; + _minMipCountBlockCompressed = Math::Min(header.MipLevels - lastMip + 1, header.MipLevels); } // Request resource streaming