From 4f036c530ea45e1d3940dc5f319674324be045a5 Mon Sep 17 00:00:00 2001 From: bruno-dasilva <8520801+bruno-dasilva@users.noreply.github.com> Date: Mon, 3 Aug 2026 03:15:53 -0700 Subject: [PATCH] fix(LuaVBO): CopyTo() now properly manages cpu-side copies of the data (#3167) Prior to this change, LuaVBOImpl::CopyTo would copy data on the GPU side but then the CPU side would remain as uninitialized data. Then something could take the uninitialized cpu side data, and push some or all of it to the GPU, leading to garbage memory. Co-authored-by: Bruno Da Silva --- rts/Lua/LuaVBOImpl.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/rts/Lua/LuaVBOImpl.cpp b/rts/Lua/LuaVBOImpl.cpp index 75cb5265d16..91b936303cb 100644 --- a/rts/Lua/LuaVBOImpl.cpp +++ b/rts/Lua/LuaVBOImpl.cpp @@ -1493,6 +1493,17 @@ bool LuaVBOImpl::CopyTo(const std::shared_ptr& destVBO, int copySize auto result = vbo->CopyTo(*destVBO->vbo, static_cast(copySizeInBytes)); + // VBO::CopyTo only moves GPU->GPU. We need to also copy over the CPU-side bufferData. + if (result && bufferData != nullptr && destVBO->bufferData != nullptr && copySizeInBytes > 0) { + const auto n = std::min({ + static_cast(copySizeInBytes), + bufferSizeInBytes, + destVBO->bufferSizeInBytes + }); + if (n > 0) + memcpy(destVBO->bufferData, bufferData, n); + } + if (!wasBound) vbo->Unbind();