diff --git a/LuaScript.Runtime/Engine/LuaJitWorker.cs b/LuaScript.Runtime/Engine/LuaJitWorker.cs index 47cfa5c..7180d03 100644 --- a/LuaScript.Runtime/Engine/LuaJitWorker.cs +++ b/LuaScript.Runtime/Engine/LuaJitWorker.cs @@ -818,7 +818,7 @@ namespace LuaScript.Engine private void EnsureWorker(int width, int height, int stringCapacity) { - long required = NativeProtocol.PixelOffset(stringCapacity) + (long)width * height * 4; + long required = NativeProtocol.PixelOffset(stringCapacity) + (long)width * height * 4 + NativeProtocol.ShaderRegionBytes; if (_alive && _process is { HasExited: false } && _stringParamsCapacity == stringCapacity && required <= _allocatedSize) return; diff --git a/LuaScript.Runtime/Engine/NativeProtocol.cs b/LuaScript.Runtime/Engine/NativeProtocol.cs index 18f3a56..cf1b435 100644 --- a/LuaScript.Runtime/Engine/NativeProtocol.cs +++ b/LuaScript.Runtime/Engine/NativeProtocol.cs @@ -187,6 +187,9 @@ namespace LuaScript.Engine public static long ShaderImageOffset(long bufferSize) => ShaderConstantsOffset(bufferSize) + ShaderConstantsMax * 4; public static long BufferSize(int width, int height, int stringCapacity) => - PixelOffset(stringCapacity) + Math.Max((long)width * height * 4, MaxPixelBufferSize) + ShaderRegionBytes; + PixelOffset(stringCapacity) + PixelRegionSize(width, height) + ShaderRegionBytes; + + public static long PixelRegionSize(int width, int height) => + (Math.Max((long)width * height * 4, MaxPixelBufferSize) + 7) & ~7L; } }