From a5567a804dfcc6465fd627a16a54dd53e612ed20 Mon Sep 17 00:00:00 2001 From: routersys Date: Thu, 2 Jul 2026 14:20:01 +0900 Subject: [PATCH] =?UTF-8?q?copybuffer=E3=81=AE=E8=A4=87=E8=A3=BD=E3=82=92?= =?UTF-8?q?=E3=83=90=E3=83=83=E3=83=95=E3=82=A1=E5=86=8D=E5=88=A9=E7=94=A8?= =?UTF-8?q?=E3=81=B8=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LuaScript/AviUtlScriptContext.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/LuaScript/AviUtlScriptContext.cs b/LuaScript/AviUtlScriptContext.cs index 2574a52..fde07f7 100644 --- a/LuaScript/AviUtlScriptContext.cs +++ b/LuaScript/AviUtlScriptContext.cs @@ -185,20 +185,29 @@ namespace LuaScript private bool TryWriteBuffer(string id, byte[] data, int width, int height) { + int n = width * height * 4; switch (BufferKind(id, out string key)) { case 'o': - ReplaceBuffer((byte[])data.Clone(), width, height); + if (_copyOutputBuffer is null || _copyOutputBuffer.Length != n) + _copyOutputBuffer = new byte[n]; + Buffer.BlockCopy(data, 0, _copyOutputBuffer, 0, n); + ReplaceBuffer(_copyOutputBuffer, width, height); return true; case 't': case 'c': - _buffers[key] = ((byte[])data.Clone(), width, height); + if (!_buffers.TryGetValue(key, out var existing) || existing.Data.Length != n) + existing.Data = new byte[n]; + Buffer.BlockCopy(data, 0, existing.Data, 0, n); + _buffers[key] = (existing.Data, width, height); return false; default: return false; } } + private byte[]? _copyOutputBuffer; + private static char BufferKind(string id, out string key) { key = string.Empty;