diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1ShaderCompiler.cs b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1ShaderCompiler.cs index 8e3f9ae9..fdf1d322 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1ShaderCompiler.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1ShaderCompiler.cs @@ -37,10 +37,13 @@ public static class D2D1ShaderCompiler int sourceWrittenBytes = Encoding.ASCII.GetBytes(hlslSource, sourceBuffer); // Encode the entry point to ASCII - int maxEntryPointLength = Encoding.ASCII.GetMaxByteCount(entryPoint.Length); + int maxEntryPointLength = Encoding.ASCII.GetMaxByteCount(entryPoint.Length) + 1; byte[] entryPointBuffer = ArrayPool.Shared.Rent(maxEntryPointLength); int entryPointWrittenBytes = Encoding.ASCII.GetBytes(entryPoint, entryPointBuffer); + // The entry point has to be null-terminated + entryPointBuffer[entryPointWrittenBytes] = (byte)'\0'; + ReadOnlySpan sourceAscii = sourceBuffer.AsSpan(0, sourceWrittenBytes); ReadOnlySpan entryPointAscii = entryPointBuffer.AsSpan(0, entryPointWrittenBytes); @@ -56,7 +59,7 @@ public static class D2D1ShaderCompiler /// Compiles a new HLSL shader from the input source code. /// /// The HLSL source code to compile (in ASCII). - /// The entry point of the shader being compiled (in ASCII). + /// The entry point of the shader being compiled (in ASCII, null-terminated). /// The shader profile to use to compile the shader. /// The compiler options to use to compile the shader. /// The bytecode for the compiled shader.