From 8339a8f533c12a5b10704643b9ea780ac5b5a9d3 Mon Sep 17 00:00:00 2001 From: sablib Date: Mon, 11 Nov 2024 14:10:29 +0800 Subject: [PATCH] fix TypedArray set (#17817) * fix TypedArray set * Fix TypedArrayTemp::set function templates --- native/cocos/core/TypedArray.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/native/cocos/core/TypedArray.h b/native/cocos/core/TypedArray.h index 64b5302630e..ced002aa023 100644 --- a/native/cocos/core/TypedArray.h +++ b/native/cocos/core/TypedArray.h @@ -192,9 +192,9 @@ class TypedArrayTemp { } void set(ArrayBuffer *buffer, uint32_t offset) { - CC_ASSERT(buffer->byteLength() + offset <= _byteEndPos); + CC_ASSERT(buffer->byteLength() + _byteOffset + offset * BYTES_PER_ELEMENT <= _byteEndPos); CC_ASSERT(_buffer); - memcpy(_buffer->_data + offset, buffer->_data, buffer->byteLength()); + memcpy(_buffer->_data + _byteOffset + offset * BYTES_PER_ELEMENT, buffer->_data, buffer->byteLength()); } template @@ -291,7 +291,7 @@ template template typename std::enable_if_t::value, void> TypedArrayTemp::set(const TypedArrayTemp &array, uint32_t offset) { CC_ASSERT(_buffer); - uint32_t dstByteOffset = offset * BYTES_PER_ELEMENT; + uint32_t dstByteOffset = _byteOffset + offset * BYTES_PER_ELEMENT; uint32_t srcByteOffset = array.byteOffset(); uint32_t srcCount = array.length(); CC_ASSERT(dstByteOffset + srcCount * TypedArrayTemp::BYTES_PER_ELEMENT <= _byteEndPos); @@ -302,7 +302,7 @@ template template typename std::enable_if_t::value, void> TypedArrayTemp::set(const TypedArrayTemp &array, uint32_t offset) { CC_ASSERT(_buffer); - uint32_t dstByteOffset = offset * BYTES_PER_ELEMENT; + uint32_t dstByteOffset = _byteOffset + offset * BYTES_PER_ELEMENT; uint32_t srcByteOffset = array.byteOffset(); uint32_t srcCount = array.length(); uint32_t remainCount = (_byteEndPos - dstByteOffset) / BYTES_PER_ELEMENT;