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;