From b4cebf2c7e6fdddf520945bb7e09329ed1b967cb Mon Sep 17 00:00:00 2001 From: sablib Date: Wed, 6 Nov 2024 19:36:57 +0800 Subject: [PATCH 1/2] fix TypedArray set --- native/cocos/core/TypedArray.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/native/cocos/core/TypedArray.h b/native/cocos/core/TypedArray.h index 64b5302630e..2d0faa649e3 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 From 719d33b8f3f0e6ad820434b84184ff19d1ce0a65 Mon Sep 17 00:00:00 2001 From: sablib Date: Thu, 7 Nov 2024 22:20:28 +0800 Subject: [PATCH 2/2] Fix TypedArrayTemp::set function templates --- native/cocos/core/TypedArray.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/native/cocos/core/TypedArray.h b/native/cocos/core/TypedArray.h index 2d0faa649e3..ced002aa023 100644 --- a/native/cocos/core/TypedArray.h +++ b/native/cocos/core/TypedArray.h @@ -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;