From fbc1e6c8615765f7fdffff8d1a048dc0f84812f7 Mon Sep 17 00:00:00 2001 From: Wojciech Figat Date: Fri, 8 Apr 2022 13:53:59 +0200 Subject: [PATCH] Fix shader source code encoding error on compilation error --- .../Graphics/Shaders/Cache/ShaderAssetBase.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Source/Engine/Graphics/Shaders/Cache/ShaderAssetBase.cpp b/Source/Engine/Graphics/Shaders/Cache/ShaderAssetBase.cpp index d84231406..efaed6d8f 100644 --- a/Source/Engine/Graphics/Shaders/Cache/ShaderAssetBase.cpp +++ b/Source/Engine/Graphics/Shaders/Cache/ShaderAssetBase.cpp @@ -282,16 +282,18 @@ bool ShaderAssetBase::LoadShaderCache(ShaderCacheResult& result) editorDefine.Definition = "1"; #endif InitCompilationOptions(options); - if (ShadersCompilation::Compile(options)) + const bool failed = ShadersCompilation::Compile(options); + + // Encrypt source code + Encryption::EncryptBytes(reinterpret_cast(source), sourceLength); + + if (failed) { LOG(Error, "Failed to compile shader '{0}'", parent->ToString()); return true; } LOG(Info, "Shader '{0}' compiled! Cache size: {1} bytes", parent->ToString(), cacheStream.GetPosition()); - // Encrypt source code - Encryption::EncryptBytes(reinterpret_cast(source), sourceLength); - // Save compilation result (based on current caching policy) if (cachingMode == ShaderStorage::CachingMode::AssetInternal) { @@ -345,7 +347,7 @@ bool ShaderAssetBase::LoadShaderCache(ShaderCacheResult& result) result.Data.Link(cacheChunk->Data); } #if COMPILE_WITH_SHADER_CACHE_MANAGER - // Check if has cached shader + // Check if has cached shader else if (cachedEntry.IsValid() || ShaderCacheManager::TryGetEntry(shaderProfile, parent->GetID(), cachedEntry)) { // Load results from cache