diff --git a/Source/Editor/Cooker/Steps/CookAssetsStep.cpp b/Source/Editor/Cooker/Steps/CookAssetsStep.cpp
index ea9bad971..396626fc1 100644
--- a/Source/Editor/Cooker/Steps/CookAssetsStep.cpp
+++ b/Source/Editor/Cooker/Steps/CookAssetsStep.cpp
@@ -322,8 +322,6 @@ bool ProcessShaderBase(CookAssetsStep::AssetCookData& data, ShaderAssetBase* ass
auto sourceLength = sourceChunk->Size();
Encryption::DecryptBytes((byte*)source, sourceLength);
source[sourceLength - 1] = 0;
- while (sourceLength > 2 && source[sourceLength - 1] == 0)
- sourceLength--;
// Init shader cache output stream
// TODO: reuse MemoryWriteStream per cooking process to reduce dynamic memory allocations
diff --git a/Source/Engine/ShadersCompilation/ShadersCompilation.cpp b/Source/Engine/ShadersCompilation/ShadersCompilation.cpp
index f8f548dab..97e30d1a4 100644
--- a/Source/Engine/ShadersCompilation/ShadersCompilation.cpp
+++ b/Source/Engine/ShadersCompilation/ShadersCompilation.cpp
@@ -60,7 +60,7 @@ public:
ShadersCompilationService ShadersCompilationServiceInstance;
-bool ShadersCompilation::Compile(const ShaderCompilationOptions& options)
+bool ShadersCompilation::Compile(ShaderCompilationOptions& options)
{
PROFILE_CPU_NAMED("Shader.Compile");
@@ -86,6 +86,10 @@ bool ShadersCompilation::Compile(const ShaderCompilationOptions& options)
return true;
}
+ // Adjust input source length if it ends with null
+ while (options.SourceLength > 2 && options.Source[options.SourceLength - 1] == 0)
+ options.SourceLength--;
+
const DateTime startTime = DateTime::NowUTC();
const FeatureLevel featureLevel = RenderTools::GetFeatureLevel(options.Profile);
diff --git a/Source/Engine/ShadersCompilation/ShadersCompilation.h b/Source/Engine/ShadersCompilation/ShadersCompilation.h
index 19ee6d9f5..30f269e6e 100644
--- a/Source/Engine/ShadersCompilation/ShadersCompilation.h
+++ b/Source/Engine/ShadersCompilation/ShadersCompilation.h
@@ -20,7 +20,7 @@ public:
///
/// Compilation options
/// True if failed, otherwise false
- static bool Compile(const ShaderCompilationOptions& options);
+ static bool Compile(ShaderCompilationOptions& options);
///
/// Registers shader asset for the automated reloads on source includes changes.